Skip to content

Commit

Permalink
Do not parse default values as types
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jan 12, 2023
1 parent 6bbf172 commit a390977
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pytype/pyi/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ def visit_Pyval(self, node):
if node.type == "str" and not self.subscripted:
return self.convert_late_annotation(node.value)

def visit_arg(self, node):
# Visit only the annotation, not the default (which may be a
# string but should not be interpreted as a type annotation).
if node.annotation is not None:
self.visit(node.annotation)

def visit_Tuple(self, node):
return tuple(node.elts)

Expand Down
7 changes: 7 additions & 0 deletions pytype/pyi/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,13 @@ def test_params(self):
self.check("def foo(x: int, y: str, z: bool,) -> int: ...",
"def foo(x: int, y: str, z: bool) -> int: ...")

def test_defaults(self):
self.check("""
def f(x: int = 3, y: str = "y") -> None: ...
""", """
def f(x: int = ..., y: str = ...) -> None: ...
""")

def test_star_params(self):
self.check("def foo(*, x) -> str: ...")
self.check("def foo(x: int, *args) -> str: ...")
Expand Down

0 comments on commit a390977

Please sign in to comment.