Skip to content

Commit d09c210

Browse files
committed
Add failing test of inference for slices called type
Ref pylint-dev/pylint#4083
1 parent adae306 commit d09c210

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/unittest_inference.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,44 @@ def test():
39743974
with self.assertRaises(exceptions.AstroidTypeError):
39753975
inferred.getitem(nodes.Const("4"))
39763976

3977+
def test_infer_arg_called_type_is_uninferable(self):
3978+
node = extract_node(
3979+
"""
3980+
def func(type):
3981+
type #@
3982+
"""
3983+
)
3984+
inferred = next(node.infer())
3985+
assert inferred is util.Uninferable
3986+
3987+
@pytest.mark.skipif(sys.version_info < (3, 8), reason="only fails on Python 3.9")
3988+
def test_infer_arg_called_object_when_used_as_index_is_uninferable(self):
3989+
node = extract_node(
3990+
"""
3991+
def func(object):
3992+
['list'][
3993+
object #@
3994+
]
3995+
"""
3996+
)
3997+
inferred = next(node.infer())
3998+
assert inferred is util.Uninferable
3999+
4000+
@pytest.mark.skipif(sys.version_info < (3, 8), reason="only fails on Python 3.9")
4001+
def test_infer_arg_called_type_when_used_as_index_is_uninferable(self):
4002+
# Only this case seems to fail
4003+
node = extract_node(
4004+
"""
4005+
def func(type):
4006+
['list'][
4007+
type #@
4008+
]
4009+
"""
4010+
)
4011+
inferred = next(node.infer())
4012+
assert not isinstance(inferred, nodes.ClassDef) # was inferred as builtins.type
4013+
assert inferred is util.Uninferable
4014+
39774015

39784016
class GetattrTest(unittest.TestCase):
39794017
def test_yes_when_unknown(self):

0 commit comments

Comments
 (0)