c = foo.method.x d = os.chmod.x """, deep=True, solve_unknowns=True) self.assertTypesMatchPytd( ty, """ os = ... # type: module def f() -> NoneType class Foo(object): def method(self) -> NoneType foo = ... # type: Foo a = ... # type: int b = ... # type: complex c = ... # type: complex d = ... # type: float """) @unittest.skip("broken by typeshed upgrade") def testJson(self): ty = self.Infer(""" import json """) self.assertTypesMatchPytd(ty, """ json = ... # type: module """) if __name__ == "__main__": test_inference.main()
def test_isinstance(self): sourcecode = textwrap.dedent(""" x = ... # type: `~unknown1` def `~isinstance`(object: int, class_or_type_or_tuple: tuple[nothing]) -> `~unknown1` class `~unknown1`(object): pass """) expected = textwrap.dedent(""" x = ... # type: bool """).strip() ast = parser.parse_string(sourcecode) ast = convert_structural.convert_pytd(ast, self.builtins_pytd) self.assertMultiLineEqual(pytd.Print(ast), expected) def test_match_superclass(self): mapping = self.parse_and_solve(""" class Base1(): def f(self, x:Base1) -> Base2 class Base2(): def g(self) -> Base1 class Foo(Base1, Base2): pass class `~unknown1`(): def f(self, x:Base1) -> Base2 """) self.assertItemsEqual(["Foo", "Base1"], mapping["~unknown1"]) if __name__ == "__main__": test_inference.main()