diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2022-06-05 16:37:36 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-05 22:37:36 +0200 |
| commit | e57ac42bca80c105bbdad4bae61637b39288a47b (patch) | |
| tree | 721b44021b69181ffe0df0c51f806307b2c9bfb2 /tests | |
| parent | c2135324b5fcb045000fbaee52e6c3f19b02c1f5 (diff) | |
| download | astroid-git-e57ac42bca80c105bbdad4bae61637b39288a47b.tar.gz | |
Infer instances of builtins created by __new__() (#1590)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unittest_inference.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py index b4313fa3..6ae4f40a 100644 --- a/tests/unittest_inference.py +++ b/tests/unittest_inference.py @@ -3768,6 +3768,33 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): ] self.assertEqual(titles, ["Catch 22", "Ubik", "Grimus"]) + @staticmethod + def test_builtin_new() -> None: + ast_node = extract_node("int.__new__(int, 42)") + inferred = next(ast_node.infer()) + assert isinstance(inferred, nodes.Const) + assert inferred.value == 42 + + ast_node2 = extract_node("int.__new__(int)") + inferred2 = next(ast_node2.infer()) + assert isinstance(inferred2, Instance) + assert not isinstance(inferred2, nodes.Const) + assert inferred2._proxied is inferred._proxied + + ast_node3 = extract_node( + """ + x = 43 + int.__new__(int, x) #@ + """ + ) + inferred3 = next(ast_node3.infer()) + assert isinstance(inferred3, nodes.Const) + assert inferred3.value == 43 + + ast_node4 = extract_node("int.__new__()") + with pytest.raises(InferenceError): + next(ast_node4.infer()) + @pytest.mark.xfail(reason="Does not support function metaclasses") def test_function_metaclasses(self): # These are not supported right now, although |
