Skip to content

Commit 14167bc

Browse files
committed
Widen the return type of ast.parse in a Python 3 test.
python/typeshed#2859 changed the return type. Module is a subclass of AST, so it's still correct, just less precise. Based on the PR description, this change was intentional. PiperOrigin-RevId: 239423111
1 parent b3aedfe commit 14167bc

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

pytype/tests/py2/test_stdlib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
class StdlibTests(test_base.TargetPython27FeatureTest):
77
"""Tests for files in typeshed/stdlib."""
88

9+
def testAST(self):
10+
ty = self.Infer("""
11+
import ast
12+
def f():
13+
return ast.parse("True")
14+
""")
15+
self.assertTypesMatchPytd(ty, """
16+
ast = ... # type: module
17+
def f() -> _ast.Module
18+
""")
19+
920
def testPosix(self):
1021
ty = self.Infer("""
1122
import posix

pytype/tests/py3/test_stdlib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ class StdlibTestsFeatures(test_base.TargetPython3FeatureTest,
8383
test_utils.TestCollectionsMixin):
8484
"""Tests for files in typeshed/stdlib."""
8585

86+
def testAST(self):
87+
ty = self.Infer("""
88+
import ast
89+
def f():
90+
return ast.parse("True")
91+
""")
92+
self.assertTypesMatchPytd(ty, """
93+
ast = ... # type: module
94+
def f() -> _ast.AST
95+
""")
96+
8697
def testCollectionsSmokeTest(self):
8798
# These classes are not fully implemented in typing.py.
8899
self.Check("""

pytype/tests/test_stdlib.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
class StdlibTests(test_base.TargetIndependentTest):
77
"""Tests for files in typeshed/stdlib."""
88

9-
def testAST(self):
10-
ty = self.Infer("""
11-
import ast
12-
def f():
13-
return ast.parse("True")
14-
""")
15-
self.assertTypesMatchPytd(ty, """
16-
ast = ... # type: module
17-
def f() -> _ast.Module
18-
""")
19-
209
def testUrllib(self):
2110
ty = self.Infer("""
2211
import urllib

0 commit comments

Comments
 (0)