Skip to content

Commit

Permalink
Skip parser logic and test requiring ast.unparse in 3.8.
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen152 committed Nov 16, 2023
1 parent b9e15c9 commit c4bd053
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pytype/pyi/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ def _convert_annotated(x):
"""Convert everything to a string to store it in pytd.Annotated."""
if isinstance(x, types.Pyval):
return x.repr_str()
elif isinstance(x, astlib.AST):
# TODO(rechen): ast.unparse is new in Python 3.9, so we can drop the hasattr
# check once pytype stops supporting 3.8.
elif isinstance(x, astlib.AST) and hasattr(astlib, "unparse"):
return astlib.unparse(x)
elif isinstance(x, dict):
return metadata.to_string(x)
Expand Down
2 changes: 2 additions & 0 deletions pytype/pyi/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pytype.pyi import parser_test_base
from pytype.pytd import pytd
from pytype.tests import test_base
from pytype.tests import test_utils

import unittest

Expand Down Expand Up @@ -2846,6 +2847,7 @@ class Foo:
y: Annotated[int, {'tag': 'call', 'fn': 'unit', 'posargs': ('s',), 'kwargs': {'exp': 9}}]
""")

@test_utils.skipBeforePy((3, 9), "requires ast.unparse, new in 3.9")
def test_name(self):
self.check("""
from typing_extensions import Annotated
Expand Down

0 comments on commit c4bd053

Please sign in to comment.