Skip to content

Commit f06005e

Browse files
Generated docs for missing docstrings (#241)
# Motivation Many attributes are missing docstrings # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [x] I have added tests for my changes - [x] I have updated the documentation or added new documentation as needed
1 parent 2026481 commit f06005e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+314
-98
lines changed

src/codegen/git/models/pr_options.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55

66
@apidoc
77
class PROptions(BaseModel):
8-
"""Options for generating a PR."""
8+
"""Options for generating a PR.
9+
10+
Attributes:
11+
title: The title of the pull request.
12+
body: The body content of the pull request.
13+
labels: A list of labels to be added to the pull request.
14+
force_push_head_branch: Whether to force push the head branch.
15+
"""
916

1017
title: str | None = None
1118
body: str | None = None

src/codegen/sdk/code_generation/doc_utils/generate_docs_json.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,25 @@
99
from codegen.sdk.core.codebase import Codebase
1010
from codegen.sdk.core.placeholder.placeholder_type import TypePlaceholder
1111

12-
ATTRIBUTES_TO_IGNORE = ["G", "node_id", "angular"]
13-
14-
15-
def generate_docs_json(codebase: Codebase, head_commit: str) -> dict[str, dict[str, Any]]:
12+
ATTRIBUTES_TO_IGNORE = [
13+
"G",
14+
"node_id",
15+
"angular",
16+
"model_config",
17+
"constructor_keyword",
18+
"viz",
19+
"console",
20+
"items",
21+
"node_type",
22+
"ts_node",
23+
"file_node_id",
24+
"G",
25+
"statement_type",
26+
"assignment_types",
27+
]
28+
29+
30+
def generate_docs_json(codebase: Codebase, head_commit: str, raise_on_missing_docstring: bool = False) -> dict[str, dict[str, Any]]:
1631
"""Update documentation table for classes, methods and attributes in the codebase.
1732
1833
Args:
@@ -23,7 +38,6 @@ def generate_docs_json(codebase: Codebase, head_commit: str) -> dict[str, dict[s
2338
"""
2439
codegen_sdk_docs = GSDocs(classes=[])
2540
types_cache = {}
26-
attr_cache = {}
2741

2842
def process_class_doc(cls):
2943
"""Update or create documentation for a class."""
@@ -110,22 +124,22 @@ def process_attribute(attr, cls, cls_doc, seen_methods):
110124
return
111125

112126
attr_path = create_path(attr, cls)
113-
original_attr_path = create_path(attr)
114127

115-
if original_attr_path not in attr_cache:
116-
description = attr.docstring(cls)
117-
attr_return_type = []
118-
if r_type := get_type_str(attr):
119-
if isinstance(r_type, TypePlaceholder):
120-
resolved_types = []
121-
else:
122-
resolved_types = r_type.resolved_types
123-
r_type_source = replace_multiple_types(codebase=codebase, input_str=r_type.source, resolved_types=resolved_types, parent_class=cls, parent_symbol=attr, types_cache=types_cache)
124-
attr_return_type.append(r_type_source)
128+
description = attr.docstring(attr.parent_class)
129+
if raise_on_missing_docstring and not description:
130+
msg = f"Attribute {attr.parent_class.name}.{attr.name} does not have a docstring"
131+
raise ValueError(msg)
132+
attr_return_type = []
133+
if r_type := get_type_str(attr):
134+
if isinstance(r_type, TypePlaceholder):
135+
resolved_types = []
136+
else:
137+
resolved_types = r_type.resolved_types
138+
r_type_source = replace_multiple_types(codebase=codebase, input_str=r_type.source, resolved_types=resolved_types, parent_class=cls, parent_symbol=attr, types_cache=types_cache)
139+
attr_return_type.append(r_type_source)
125140

126-
attr_cache[original_attr_path] = {"description": description, "attr_return_type": attr_return_type}
141+
attr_info = {"description": description, "attr_return_type": attr_return_type}
127142

128-
attr_info = attr_cache[original_attr_path]
129143
meta_data = {"parent": create_path(attr.parent_class), "path": attr.file.filepath}
130144

131145
return MethodDoc(

src/codegen/sdk/codebase/span.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ def range_json_schema() -> JsonSchemaValue:
5454

5555
@apidoc
5656
class Span(BaseModel):
57-
"""Range within the codebase"""
57+
"""Range within the codebase
58+
59+
Attributes:
60+
range: Adapter for the range within the codebase.
61+
filepath: The path to the file associated with the range.
62+
"""
5863

5964
model_config = ConfigDict(
6065
frozen=True,

src/codegen/sdk/core/assignment.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,14 @@
4545
class Assignment(Symbol[Parent, ...], Typeable[Parent, ...], HasValue, Generic[Parent]):
4646
"""Represents an assignment for a single variable within an assignment statement.
4747
48-
Attributes:
49-
left: The left side of the assignment
50-
right: The right side of the assignment
51-
5248
Example:
5349
```typescript
5450
var z
5551
var z = 5
5652
```
53+
54+
Attributes:
55+
symbol_type: The type of symbol, set to SymbolType.GlobalVar.
5756
"""
5857

5958
_left: Expression[Self]

src/codegen/sdk/core/class_definition.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@
5151

5252
@apidoc
5353
class Class(Inherits[TType], HasBlock[TCodeBlock, TDecorator], Callable[TParameter, TType], HasAttribute[TFunction | Attribute], Generic[TFunction, TDecorator, TCodeBlock, TParameter, TType]):
54-
"""Abstract representation of a Class definition."""
54+
"""Abstract representation of a Class definition.
55+
56+
Attributes:
57+
symbol_type: The type of symbol, set to SymbolType.Class.
58+
constructor_keyword: The keyword used to identify the constructor method.
59+
parent_classes: The parent classes of this class, if any.
60+
"""
5561

5662
symbol_type = SymbolType.Class
5763
constructor_keyword = None

src/codegen/sdk/core/codebase.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@
106106
class Codebase(Generic[TSourceFile, TDirectory, TSymbol, TClass, TFunction, TImport, TGlobalVar, TInterface, TTypeAlias, TParameter, TCodeBlock]):
107107
"""This class provides the main entrypoint for most programs to analyzing and manipulating codebases.
108108
109-
It provides a high-level interface to interact with the codebase graph, and provides methods to access and manipulate files, directories, symbols, and other entities in the codebase.
109+
Attributes:
110+
viz: Manages visualization of the codebase graph.
111+
repo_path: The path to the repository.
112+
console: Manages console output for the codebase.
110113
"""
111114

112115
_op: RepoOperator | RemoteRepoOperator

src/codegen/sdk/core/dataclasses/usage.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Usage:
2727
Attributes:
2828
match: The exact match of the usage
2929
usage_symbol: The symbol this object is used in
30+
imported_by: The import statement that brought this symbol into scope, or None if not imported
3031
usage_type: How this symbol was used
3132
kind: Where this symbol was used (IE: in a type parameter or in the body of the class, etc)
3233
"""
@@ -62,15 +63,17 @@ class UsageKind(IntEnum):
6263
6364
Attributes:
6465
SUBCLASS: Used in symbol inheritance.
65-
TYPE_ANNOTATION: Used as a type annotation on a parameter or assignment statement.
66+
TYPED_PARAMETER: Used as a typed parameter in a function/method.
67+
TYPE_ANNOTATION: Used as a type annotation on a parameter or assignment statement.
6668
BODY: Usage within the body of a function/method.
6769
DECORATOR: Usage within a decorator.
68-
RETURN_TYPE: Used as a return type annotation
70+
RETURN_TYPE: Used as a return type annotation.
6971
TYPE_DEFINITION: Used in a type alias.
7072
EXPORTED_SYMBOL: Used in an export statement.
7173
EXPORTED_WILDCARD: Re-exported by a wildcard export.
7274
GENERIC: Used as a type parameter to another type.
7375
IMPORTED: Imported with an import statement.
76+
IMPORTED_WILDCARD: Imported with a wildcard import statement.
7477
DEFAULT_VALUE: Represents a default value in a function/method parameter.
7578
"""
7679

src/codegen/sdk/core/detached_symbols/code_block.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class CodeBlock(Expression[Parent], Generic[Parent, TAssignment]):
4545
function body or class body.
4646
4747
Enables various types of queries and operations on the code block.
48+
49+
Attributes:
50+
level: The indentation level of the code block.
51+
parent_block: The parent code block containing this block, or None if it is a top-level block.
4852
"""
4953

5054
level: int

src/codegen/sdk/core/directory.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@
3939
@apidoc
4040
class Directory(Generic[TFile, TSymbol, TImportStatement, TGlobalVar, TClass, TFunction, TImport]):
4141
"""Directory representation for codebase.
42+
4243
GraphSitter abstraction of a file directory that can be used to look for files and symbols within a specific directory.
44+
45+
Attributes:
46+
path: Absolute path of the directory.
47+
dirpath: Relative path of the directory.
48+
parent: The parent directory, if any.
49+
items: A dictionary containing files and subdirectories within the directory.
4350
"""
4451

4552
path: Path # Absolute Path

src/codegen/sdk/core/export.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
@apidoc
2323
class Export(Exportable[Parent], Generic[Parent]):
24-
"""Represents a single symbol being exported."""
24+
"""Represents a single symbol being exported.
25+
26+
Attributes:
27+
export_statement: The statement representing the export.
28+
"""
2529

2630
export_statement: ExportStatement
2731

src/codegen/sdk/core/expressions/binary_expression.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323

2424
@apidoc
2525
class BinaryExpression(Expression[Parent], Chainable, Generic[Parent]):
26-
"""Represents binary expressions, e.g. all of +,-,*,/, as well as booleaneoperations (and, or) etc."""
26+
"""Represents binary expressions, e.g. all of +,-,*,/, as well as boolean operations (and, or) etc.
27+
28+
Attributes:
29+
left: The left operand of the binary expression.
30+
right: The right operand of the binary expression.
31+
"""
2732

2833
left: Expression[Self] | None
2934
right: Expression[Self] | None

src/codegen/sdk/core/expressions/expression.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
@apidoc
1515
class Expression(Editable[Parent], Generic[Parent]):
16-
"""Represents an arbitrary Expression, such as List, Dict, Binary Expression, String."""
16+
"""Represents an arbitrary Expression, such as List, Dict, Binary Expression, String.
17+
18+
Attributes:
19+
node_type: The type of the node, set to NodeType.EXPRESSION.
20+
"""
1721

1822
node_type: NodeType = NodeType.EXPRESSION
1923

src/codegen/sdk/core/expressions/multi_expression.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121

2222
@apidoc
2323
class MultiExpression(Expression[Parent], Generic[Parent, TExpression]):
24-
"""Represents an group of Expressions, such as List, Dict, Binary Expression, String."""
24+
"""Represents an group of Expressions, such as List, Dict, Binary Expression, String.
25+
26+
Attributes:
27+
expressions: A list of expressions contained within the MultiExpression.
28+
"""
2529

2630
expressions: list[TExpression]
2731

src/codegen/sdk/core/expressions/string.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class String(Expression[Parent], Builtin, Generic[Parent]):
2626
2727
Attributes:
2828
content: The content of the string
29-
expressions: embedded expressions in the string, only applicable for templated or formatted strings
29+
content_nodes: A collection of string fragments and escape sequences in TS, or a single string content in Python.
30+
expressions: Embedded expressions in the string, only applicable for templated or formatted strings.
3031
"""
3132

3233
content: str

src/codegen/sdk/core/expressions/subscript_expression.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class SubscriptExpression(Expression[Parent], Resolvable[Parent], Generic[Object
2626
2727
Examples:
2828
A[]
29+
30+
Attributes:
31+
object: The object being indexed.
32+
indices: A list of indices used for indexing the object.
33+
2934
"""
3035

3136
object: Object

src/codegen/sdk/core/expressions/ternary_expression.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919

2020
@apidoc
2121
class TernaryExpression(Expression[Parent], Chainable, Generic[Parent]):
22-
"""Any ternary expression in the code where a condition will determine branched execution."""
22+
"""Any ternary expression in the code where a condition will determine branched execution.
23+
24+
Attributes:
25+
condition: The condition expression that determines which branch to execute.
26+
consequence: The expression to execute if the condition is true.
27+
alternative: The expression to execute if the condition is false.
28+
"""
2329

2430
condition: Expression[Self] | None
2531
consequence: Expression[Self] | None

src/codegen/sdk/core/external_module.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ class ExternalModule(
2929
):
3030
"""Represents an external module, like `datetime`, that can be referenced.
3131
32-
These are only added to the graph during import resolution and will not exist in a local file's
33-
subgraph. This is because we don't know what an import is referencing or resolves to until we
34-
see the full codebase.
32+
These are only added to the graph during import resolution and will not exist in a local file's subgraph. This is because we don't know what an import is referencing or resolves to until we see
33+
the full codebase.
34+
35+
Attributes:
36+
node_type: The type of node, set to NodeType.EXTERNAL.
3537
"""
3638

3739
node_type: Literal[NodeType.EXTERNAL] = NodeType.EXTERNAL

src/codegen/sdk/core/file.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class File(Editable[None]):
5454
"""Represents a generic file.
5555
5656
Could represent a source file or a non-code file such as a markdown file or image file.
57+
58+
Attributes:
59+
name: The name of the file.
60+
file_path: The relative file path as a string.
61+
path: The absolute path of the file as a Path object.
62+
node_type: The type of node, set to NodeType.FILE.
5763
"""
5864

5965
name: str
@@ -432,6 +438,9 @@ class SourceFile(
432438
433439
Enables creating, reading, updating, and deleting files and searching through their contents,
434440
etc.
441+
442+
Attributes:
443+
code_block: Represents the block of code contained in the file.
435444
"""
436445

437446
code_block: TCodeBlock

src/codegen/sdk/core/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Function(
5050
"""Abstract representation of a Function.
5151
5252
Attributes:
53-
return_type: the return type annotation of the function
53+
symbol_type: The type of symbol, set to SymbolType.Function.
5454
"""
5555

5656
symbol_type = SymbolType.Function

src/codegen/sdk/core/import_resolution.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,14 @@ class ImportResolution(Generic[TSourceFile]):
6161
class Import(Usable[ImportStatement], Chainable, Generic[TSourceFile], HasAttribute[TSourceFile]):
6262
"""Represents a single symbol being imported.
6363
64-
For example, this is one `Import` in Python (and similar applies to Typescript, etc.):
65-
```
66-
from a.b import c
67-
```
68-
69-
This is two separate `Import` in Python:
70-
```
71-
from a.b import c, d # one import for each `c` and `d`
72-
```
7364
Attributes:
65+
to_file_id: The node ID of the file to which this import belongs.
66+
module: The module from which the symbol is being imported, if applicable.
7467
symbol_name: The name of the symbol being imported. For instance import a as b has a symbol_name of a.
68+
alias: The alias of the imported symbol, if one exists.
69+
node_type: The type of node, set to NodeType.IMPORT.
70+
import_type: The type of import, indicating how the symbol is imported.
71+
import_statement: The statement that this import is part of.
7572
import_statement: the ImportStatement that this import belongs to
7673
"""
7774

src/codegen/sdk/core/interfaces/callable.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class Callable(Usable, Generic[TParameter, TType]):
4343
"""Any symbol that can be invoked with arguments eg.
4444
4545
Function, Class, Decorator, ExternalModule
46+
47+
Attributes:
48+
return_type: The type of value returned by the callable, or a placeholder.
4649
"""
4750

4851
_parameters: SymbolGroup[TParameter, Self] | list[TParameter]

src/codegen/sdk/core/interfaces/editable.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ def _is_empty_container(text: str) -> bool:
9999
class Editable(JSONable, Generic[Parent]):
100100
"""An editable instance is an abstract text representation of any text in a file.
101101
102-
The editable APIs enables text search and edit within the given Editable wrapper around any
103-
group of text in a file.
102+
Attributes:
103+
ts_node: The TreeSitter node associated with this Editable instance.
104+
file_node_id: The unique identifier for the file node.
105+
G: The codebase graph that this Editable instance is part of.
106+
parent: The parent node of this Editable instance.
107+
node_type: The type of node this Editable instance represents.
104108
"""
105109

106110
ts_node: TSNode

0 commit comments

Comments
 (0)