MCPcopy Create free account
hub / github.com/dot-agent/nextpy / visit_ClassDef

Method visit_ClassDef

scripts/pyi_generator.py:468–504  ·  view source on GitHub ↗

Visit a ClassDef node. Remove all assignments in the class body, and add a create functiondef if one does not exist. Args: node: The ClassDef node to visit. Returns: The modified ClassDef node.

(self, node: ast.ClassDef)

Source from the content-addressed store, hash-verified

466 return self.visit_Import(node)
467
468 def visit_ClassDef(self, node: ast.ClassDef) -> ast.ClassDef:
469 """Visit a ClassDef node.
470
471 Remove all assignments in the class body, and add a create functiondef
472 if one does not exist.
473
474 Args:
475 node: The ClassDef node to visit.
476
477 Returns:
478 The modified ClassDef node.
479 """
480 exec("\n".join(self.import_statements), self.type_hint_globals)
481 self.current_class = node.name
482 self._remove_docstring(node)
483 self.generic_visit(node) # Visit child nodes.
484
485 if (
486 not any(
487 isinstance(child, ast.FunctionDef) and child.name == "create"
488 for child in node.body
489 )
490 and self.current_class in self.classes
491 ):
492 # Add a new .create FunctionDef since one does not exist.
493 node.body.append(
494 _generate_component_create_functiondef(
495 node=None,
496 clz=self.classes[self.current_class],
497 type_hint_globals=self.type_hint_globals,
498 )
499 )
500 if not node.body:
501 # We should never return an empty body.
502 node.body.append(ast.Expr(value=ast.Ellipsis()))
503 self.current_class = None
504 return node
505
506 def visit_FunctionDef(self, node: ast.FunctionDef) -> Any:
507 """Visit a FunctionDef node.

Callers

nothing calls this directly

Calls 4

_remove_docstringMethod · 0.95
joinMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected