diff --git a/lib/python/pyflyby/_parse.py b/lib/python/pyflyby/_parse.py index a566f11a..76fcacc9 100644 --- a/lib/python/pyflyby/_parse.py +++ b/lib/python/pyflyby/_parse.py @@ -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 @@ -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( @@ -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 @@ -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. @@ -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: @@ -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.