Skip to content

Commit

Permalink
Widen the return type of ast.parse in a Python 3 test.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rchen152 committed Mar 21, 2019
1 parent b3aedfe commit 14167bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
11 changes: 11 additions & 0 deletions pytype/tests/py2/test_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
class StdlibTests(test_base.TargetPython27FeatureTest):
"""Tests for files in typeshed/stdlib."""

def testAST(self):
ty = self.Infer("""
import ast
def f():
return ast.parse("True")
""")
self.assertTypesMatchPytd(ty, """
ast = ... # type: module
def f() -> _ast.Module
""")

def testPosix(self):
ty = self.Infer("""
import posix
Expand Down
11 changes: 11 additions & 0 deletions pytype/tests/py3/test_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ class StdlibTestsFeatures(test_base.TargetPython3FeatureTest,
test_utils.TestCollectionsMixin):
"""Tests for files in typeshed/stdlib."""

def testAST(self):
ty = self.Infer("""
import ast
def f():
return ast.parse("True")
""")
self.assertTypesMatchPytd(ty, """
ast = ... # type: module
def f() -> _ast.AST
""")

def testCollectionsSmokeTest(self):
# These classes are not fully implemented in typing.py.
self.Check("""
Expand Down
11 changes: 0 additions & 11 deletions pytype/tests/test_stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
class StdlibTests(test_base.TargetIndependentTest):
"""Tests for files in typeshed/stdlib."""

def testAST(self):
ty = self.Infer("""
import ast
def f():
return ast.parse("True")
""")
self.assertTypesMatchPytd(ty, """
ast = ... # type: module
def f() -> _ast.Module
""")

def testUrllib(self):
ty = self.Infer("""
import urllib
Expand Down

0 comments on commit 14167bc

Please sign in to comment.