diff options
| author | Bryce Guinta <bryce.paul.guinta@gmail.com> | 2018-07-07 13:30:32 -0600 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2018-07-08 11:33:20 +0200 |
| commit | 87137def3e157909bfa571ce8a4c57a20f02d91c (patch) | |
| tree | 8625251179b60ce1e1350f09ecab4620f17a764b | |
| parent | 6c742097b12df9491f90b1ceddf694c55281d17d (diff) | |
| download | astroid-git-87137def3e157909bfa571ce8a4c57a20f02d91c.tar.gz | |
Fix type.__new__ calls with incorrect arguments creating instances
| -rw-r--r-- | astroid/bases.py | 2 | ||||
| -rw-r--r-- | astroid/tests/unittest_inference.py | 8 |
2 files changed, 4 insertions, 6 deletions
diff --git a/astroid/bases.py b/astroid/bases.py index 277ad316..c7b0cbc3 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -345,7 +345,7 @@ class UnboundMethod(Proxy): self._proxied.parent.frame().qname() == '%s.object' % BUILTINS): # XXX Avoid issue with type.__new__ inference. # https://github.com/PyCQA/astroid/issues/581 - if caller.args and len(caller.args) != 4: + if caller.args and len(caller.args) == 1: node_context = context.extra_context.get(caller.args[0]) infer = caller.args[0].infer(context=node_context) else: diff --git a/astroid/tests/unittest_inference.py b/astroid/tests/unittest_inference.py index e31d19a9..353ac23b 100644 --- a/astroid/tests/unittest_inference.py +++ b/astroid/tests/unittest_inference.py @@ -3306,13 +3306,11 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase): self.assertEqual(attributes[0].value, 1) - @pytest.mark.xfail(reason="These calls should be uninferable because they are invalid calls") def test_type__new__not_enough_arguments(self): ast_nodes = extract_node(''' - type.__new__(1) #@ - type.__new__(1, 2) #@ - type.__new__(1, 2, 3) #@ - type.__new__(1, 2, 3, 4, 5) #@ + type.__new__(type, 'foo') #@ + type.__new__(type, 'foo', ()) #@ + type.__new__(type, 'foo', (), {}, ()) #@ ''') for node in ast_nodes: with pytest.raises(InferenceError): |
