Skip to content

Commit

Permalink
more annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Oct 30, 2024
1 parent 7d9b306 commit 6a3e0a4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/python/pyflyby/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def _annotate_ast_nodes(ast_node: ast.AST) -> AnnotatedAst:


def _annotate_ast_startpos(
ast_node: ast.AST, parent_ast_node, minpos, text, flags
ast_node: ast.AST, parent_ast_node, minpos: FilePos, text: FileText, flags
) -> bool:
r"""
Annotate ``ast_node``. Set ``ast_node.startpos`` to the starting position
Expand Down Expand Up @@ -410,8 +410,8 @@ def _annotate_ast_startpos(
# Walk all nodes/fields of the AST. We implement this as a custom
# depth-first search instead of using ast.walk() or ast.NodeVisitor
# so that we can easily keep track of the preceding node's lineno.
child_minpos = minpos
is_first_child = True
child_minpos: FilePos = minpos
is_first_child: bool = True
leftstr_node = None
for child_node in _iter_child_nodes_in_order(aast_node):
leftstr = _annotate_ast_startpos(
Expand Down Expand Up @@ -954,8 +954,9 @@ def from_filename(cls, filename):
return cls.from_text(Filename(filename))

@classmethod
def from_text(cls, text, filename=None, startpos=None, flags=None,
auto_flags=False):
def from_text(
cls, text, filename=None, startpos=None, flags=None, auto_flags: bool = False
):
"""
:type text:
`FileText` or convertible
Expand Down Expand Up @@ -1153,7 +1154,7 @@ def expression_ast_node(self) -> Optional[ast.Expression]:
else:
return None

def parse(self, mode=None) -> Union[ast.Expression, ast.Module]:
def parse(self, mode: Optional[str] = None) -> Union[ast.Expression, ast.Module]:
"""
Parse the source text into an AST.
Expand All @@ -1174,7 +1175,7 @@ def parse(self, mode=None) -> Union[ast.Expression, ast.Module]:
return self.expression_ast_node
else:
raise SyntaxError
elif mode == None:
elif mode is None:
if self.expression_ast_node:
return self.expression_ast_node
else:
Expand All @@ -1185,7 +1186,7 @@ def parse(self, mode=None) -> Union[ast.Expression, ast.Module]:
else:
raise ValueError("parse(): invalid mode=%r" % (mode,))

def compile(self, mode=None):
def compile(self, mode: Optional[str] = None):
"""
Parse into AST and compile AST into code.
Expand Down

0 comments on commit 6a3e0a4

Please sign in to comment.