Skip to content

Commit

Permalink
🎨 default update = True
Browse files Browse the repository at this point in the history
  • Loading branch information
Wytamma committed Mar 15, 2024
1 parent cd6bd4f commit 1e356f3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions write_the/cst/function_and_class_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ class FunctionAndClassCollector(cst.CSTVisitor):
"""
A CSTVisitor that collects the names of functions and classes from a CST tree.
"""
def __init__(self, force, update):
def __init__(self, force, update=False):
"""
Initializes the FunctionAndClassCollector.
Args:
force (bool): Whether to force the collection of functions and classes even if they have docstrings.
update (bool): Whether to update the collection of functions and classes if they have docstrings.
"""
self.functions = []
self.classes = []
Expand All @@ -21,7 +22,7 @@ def __init__(self, force, update):

def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
"""
Visits a FunctionDef node and adds its name to the list of functions if it does not have a docstring or if `force` is `True`.
Visits a FunctionDef node and adds its name to the list of functions if it does not have a docstring or if `force` or `update` is `True`.
Args:
node (cst.FunctionDef): The FunctionDef node to visit.
Expand All @@ -40,7 +41,7 @@ def visit_FunctionDef(self, node: cst.FunctionDef) -> None:

def visit_ClassDef(self, node: cst.ClassDef) -> None:
"""
Visits a ClassDef node and adds its name to the list of classes if it does not have a docstring or if `force` is `True`. Also sets the current class name for nested function collection.
Visits a ClassDef node and adds its name to the list of classes if it does not have a docstring or if `force` or `update` is `True`. Also sets the current class name for nested function collection.
Args:
node (cst.ClassDef): The ClassDef node to visit.
Expand All @@ -61,13 +62,14 @@ def leave_ClassDef(self, node: cst.ClassDef) -> None:
self.current_class = None


def get_node_names(tree, force, update):
def get_node_names(tree, force, update=False):
"""
Gets the names of functions and classes from a CST tree.
Args:
tree (cst.CSTNode): The CST tree to traverse.
force (bool): Whether to force the collection of functions and classes even if they have docstrings.
update (bool, optional): Whether to update the collection of functions and classes if they have docstrings. Defaults to False.
Returns:
list[str]: A list of function and class names.
Expand Down

0 comments on commit 1e356f3

Please sign in to comment.