Skip to content

Commit

Permalink
Bump to python 3.9, and suppress pyre error
Browse files Browse the repository at this point in the history
  • Loading branch information
stroxler committed Jan 13, 2022
1 parent 93356fc commit 47edbbc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
17 changes: 9 additions & 8 deletions libcst/codemod/commands/convert_type_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def unpack_type_comment(
@staticmethod
def unpack_target(
target: cst.BaseExpression,
) -> UnpackedTargets:
) -> UnpackedTargets: # pyre-ignore: I'm unsure what the problem is.
"""
Take a (non-function-type) type comment and split it into
components. A type comment body should always be either a single
Expand Down Expand Up @@ -208,17 +208,18 @@ class ConvertTypeComments(VisitorBasedCodemodCommand):
"""

def __init__(self, context: CodemodContext) -> None:
if (sys.version_info.major, sys.version_info.minor) < (3, 8):
# The ast module did not get `type_comments` until Python 3.7.
# In 3.6, we should error than silently running a nonsense codemod.
if (sys.version_info.major, sys.version_info.minor) < (3, 9):
# The ast module did not get `unparse` until Python 3.9,
# or `type_comments` until Python 3.8
#
# NOTE: it is possible to use the typed_ast library for 3.6, but
# this is not a high priority right now. See, e.g., the
# mypy.fastparse module.
# For earlier versions of python, raise early instead of failing
# later. It might be possible to use libcst parsing and the typed_ast
# library to support earlier python versions, but this is not a
# high priority.
raise NotImplementedError(
"You are trying to run ConvertTypeComments on a "
+ "python version without type comment support. Please "
+ "try using python 3.8+ to run your codemod."
+ "try using Python 3.9+ to run your codemod."
)
super().__init__(context)

Expand Down
20 changes: 10 additions & 10 deletions libcst/codemod/commands/tests/test_convert_type_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class TestConvertTypeComments(CodemodTest):
maxDiff = 1500
TRANSFORM = ConvertTypeComments

def assertCodemod38Plus(self, before: str, after: str) -> None:
def assertCodemod39Plus(self, before: str, after: str) -> None:
"""
Assert that the codemod works on Python 3.8+, and that we raise
a NotImplementedError on other python versions.
Assert that the codemod works on Python 3.9+, and that we raise
a NotImplementedError on other Python versions.
"""
if (sys.version_info.major, sys.version_info.minor) < (3, 8):
if (sys.version_info.major, sys.version_info.minor) < (3, 9):
with self.assertRaises(NotImplementedError):
super().assertCodemod(before, after)
else:
Expand All @@ -36,7 +36,7 @@ def test_convert_assignments(self) -> None:
y: int = 5
z: "typing.Tuple[str, int]" = ('this', 7)
"""
self.assertCodemod38Plus(before, after)
self.assertCodemod39Plus(before, after)

def test_convert_assignments_in_context(self) -> None:
"""
Expand All @@ -60,7 +60,7 @@ class C:
def __init__(self):
self.attr1: bool = True
"""
self.assertCodemod38Plus(before, after)
self.assertCodemod39Plus(before, after)

def test_multiple_elements_in_assign_lhs(self) -> None:
before = """
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_multiple_elements_in_assign_lhs(self) -> None:
e2: str
d, (e1, e2) = foo()
"""
self.assertCodemod38Plus(before, after)
self.assertCodemod39Plus(before, after)

def test_multiple_assignments(self) -> None:
before = """
Expand All @@ -109,7 +109,7 @@ def test_multiple_assignments(self) -> None:
d: str
a, b = c, d = 'this', 'that'
"""
self.assertCodemod38Plus(before, after)
self.assertCodemod39Plus(before, after)

def test_semicolons_with_assignment(self) -> None:
"""
Expand All @@ -130,7 +130,7 @@ def test_semicolons_with_assignment(self) -> None:
z: str
y, z = baz()
"""
self.assertCodemod38Plus(before, after)
self.assertCodemod39Plus(before, after)

def test_no_change_when_type_comment_unused(self) -> None:
before = """
Expand All @@ -152,4 +152,4 @@ def test_no_change_when_type_comment_unused(self) -> None:
v = v0, v1 = (3, 5) # type: int, int
"""
after = before
self.assertCodemod38Plus(before, after)
self.assertCodemod39Plus(before, after)

0 comments on commit 47edbbc

Please sign in to comment.