We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug See below.
To Reproduce
test.py
class C: def __init__(self): def pl(i: int): return i + 1
griffe ./test.py
rich
│ │ │ E:\PythonProjects\GraiaProject\Ariadne\temp_env\lib\site-packages\griffe\agents\visitor.py:446 │ │ in handle_function │ │ │ │ 443 │ │ │ │ 444 │ │ if self.current.kind is Kind.CLASS and function.name == "__init__": │ │ 445 │ │ │ self.current = function # type: ignore[assignment] # temporary assign a f │ │ ❱ 446 │ │ │ self.generic_visit(node) │ │ 447 │ │ │ self.current = self.current.parent # type: ignore[assignment] │ │ 448 │ │ │ 449 │ def visit_functiondef(self, node: ast.FunctionDef) -> None: │ │ │ │ ╭─────────────────────────────────────── locals ───────────────────────────────────────╮ │ │ │ annotation = None │ │ │ │ arg = <ast.arg object at 0x00000226391052E0> │ │ │ │ args_kinds_defaults = <reversed object at 0x00000226395BC610> │ │ │ │ base_property = None │ │ │ │ decorators = [] │ │ │ │ default = None │ │ │ │ function = <Function('__init__', 2, 4)> │ │ │ │ kind = <ParameterKind.positional_or_keyword: 'positional or keyword'> │ │ │ │ kwargs_defaults = <reversed object at 0x00000226395BC4F0> │ │ │ │ labels = set() │ │ │ │ lineno = 2 │ │ │ │ node = <ast.FunctionDef object at 0x0000022639100700> │ │ │ │ overload = False │ │ │ │ parameters = <griffe.dataclasses.Parameters object at 0x00000226395BC5B0> │ │ │ │ posonlyargs = [] │ │ │ │ property_function = None │ │ │ │ self = <griffe.agents.visitor.Visitor object at 0x00000226395BC580> │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ E:\PythonProjects\GraiaProject\Ariadne\temp_env\lib\site-packages\griffe\agents\visitor.py:198 │ │ in generic_visit │ │ │ │ 195 │ │ for before_visitor in self.extensions.before_children_visit: │ │ 196 │ │ │ before_visitor.visit(node) │ │ 197 │ │ for child in node.children: # type: ignore[attr-defined] # noqa: WPS437 │ │ ❱ 198 │ │ │ self.visit(child) │ │ 199 │ │ for after_visitor in self.extensions.after_children_visit: │ │ 200 │ │ │ after_visitor.visit(node) │ │ 201 │ │ │ │ ╭─────────────────────────────── locals ───────────────────────────────╮ │ │ │ child = <ast.FunctionDef object at 0x00000226391058E0> │ │ │ │ node = <ast.FunctionDef object at 0x0000022639100700> │ │ │ │ self = <griffe.agents.visitor.Visitor object at 0x00000226395BC580> │ │ │ ╰──────────────────────────────────────────────────────────────────────╯ │ │ │ │ E:\PythonProjects\GraiaProject\Ariadne\temp_env\lib\site-packages\griffe\agents\visitor.py:185 │ │ in visit │ │ │ │ 182 │ │ """ │ │ 183 │ │ for before_visitor in self.extensions.before_visit: │ │ 184 │ │ │ before_visitor.visit(node) │ │ ❱ 185 │ │ super().visit(node) │ │ 186 │ │ for after_visitor in self.extensions.after_visit: │ │ 187 │ │ │ after_visitor.visit(node) │ │ 188 │ │ │ │ ╭───────────────────────────────── locals ─────────────────────────────────╮ │ │ │ __class__ = <class 'griffe.agents.visitor.Visitor'> │ │ │ │ node = <ast.FunctionDef object at 0x00000226391058E0> │ │ │ │ self = <griffe.agents.visitor.Visitor object at 0x00000226395BC580> │ │ │ ╰──────────────────────────────────────────────────────────────────────────╯ │ │ │ │ E:\PythonProjects\GraiaProject\Ariadne\temp_env\lib\site-packages\griffe\agents\base.py:19 in │ │ visit │ │ │ │ 16 │ │ Parameters: │ │ 17 │ │ │ node: The node to visit. │ │ 18 │ │ """ │ │ ❱ 19 │ │ getattr(self, f"visit_{node.kind}", self.generic_visit)(node) # type: ignore[a │ │ 20 │ │ │ 21 │ def generic_visit(self, node: ast.AST) -> None: │ │ 22 │ │ """Visit the children of a node. │ │ │ │ ╭────────────────────────────── locals ───────────────────────────────╮ │ │ │ node = <ast.FunctionDef object at 0x00000226391058E0> │ │ │ │ self = <griffe.agents.visitor.Visitor object at 0x00000226395BC580> │ │ │ ╰─────────────────────────────────────────────────────────────────────╯ │ │ │ │ E:\PythonProjects\GraiaProject\Ariadne\temp_env\lib\site-packages\griffe\agents\visitor.py:455 │ │ in visit_functiondef │ │ │ │ 452 │ │ Parameters: │ │ 453 │ │ │ node: The node to visit. │ │ 454 │ │ """ │ │ ❱ 455 │ │ self.handle_function(node) │ │ 456 │ │ │ 457 │ def visit_asyncfunctiondef(self, node: ast.AsyncFunctionDef) -> None: │ │ 458 │ │ """Visit an async function definition node. │ │ │ │ ╭────────────────────────────── locals ───────────────────────────────╮ │ │ │ node = <ast.FunctionDef object at 0x00000226391058E0> │ │ │ │ self = <griffe.agents.visitor.Visitor object at 0x00000226395BC580> │ │ │ ╰─────────────────────────────────────────────────────────────────────╯ │ │ │ │ E:\PythonProjects\GraiaProject\Ariadne\temp_env\lib\site-packages\griffe\agents\visitor.py:438 │ │ in handle_function │ │ │ │ 435 │ │ │ │ base_property.labels.add("deletable") │ │ 436 │ │ else: │ │ 437 │ │ │ self.current[node.name] = function │ │ ❱ 438 │ │ │ if self.current.overloads[function.name]: │ │ 439 │ │ │ │ function.overloads = self.current.overloads[function.name] │ │ 440 │ │ │ │ del self.current.overloads[function.name] # noqa: WPS420 │ │ 441 │ │ │ │ ╭─────────────────────────────────────── locals ───────────────────────────────────────╮ │ │ │ annotation = Name(source='int', full='int') │ │ │ │ arg = <ast.arg object at 0x00000226395BC9A0> │ │ │ │ args_kinds_defaults = <reversed object at 0x00000226395C7280> │ │ │ │ base_property = None │ │ │ │ decorators = [] │ │ │ │ default = None │ │ │ │ function = <Function('pl', 3, 4)> │ │ │ │ kind = <ParameterKind.positional_or_keyword: 'positional or keyword'> │ │ │ │ kwargs_defaults = <reversed object at 0x00000226395C7220> │ │ │ │ labels = set() │ │ │ │ lineno = 3 │ │ │ │ node = <ast.FunctionDef object at 0x00000226391058E0> │ │ │ │ overload = False │ │ │ │ parameters = <griffe.dataclasses.Parameters object at 0x00000226395C72E0> │ │ │ │ posonlyargs = [] │ │ │ │ property_function = None │ │ │ │ self = <griffe.agents.visitor.Visitor object at 0x00000226395BC580> │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────╯ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: 'NoneType' object is not subscriptable
Both async def and def will cause this problem.
async def
def
Expected behavior The file is parsed correctly.
System
griffe
Additional context Found this when building with the new mkdocstrings-python handler
mkdocstrings-python
The text was updated successfully, but these errors were encountered:
🐛 fix mkdocstrings crash
18f683a
See mkdocstrings/griffe#68
fix: Don't crash on nested functions in __init__ methods
__init__
cd5af43
Issue #68: #68
Fixed in 0.19.1! Thanks for the report 🙂
Sorry, something went wrong.
No branches or pull requests
Describe the bug
See below.
To Reproduce
test.py
griffe ./test.py
rich
traceback)Both
async def
anddef
will cause this problem.Expected behavior
The file is parsed correctly.
System
griffe
version: 0.19.0Additional context
Found this when building with the new
mkdocstrings-python
handlerThe text was updated successfully, but these errors were encountered: