Skip to content

Commit

Permalink
Add check of __getitem__ signature to instance_getitem
Browse files Browse the repository at this point in the history
  • Loading branch information
nelfin committed May 24, 2021
1 parent 3829761 commit 826d0e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 6 additions & 0 deletions astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ def getitem(self, index, context=None):
raise exceptions.InferenceError(
"Could not find __getitem__ for {node!r}.", node=self, context=context
)
if len(method.args.arguments) != 2: # (self, index)
raise exceptions.AstroidTypeError(
"__getitem__ for {node!r} does not have correct signature",
node=self,
context=context,
)
return next(method.infer_call_result(self, new_context))


Expand Down
8 changes: 0 additions & 8 deletions tests/unittest_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,6 @@ class InvalidGetitem2(object):
NoGetitem()[4] #@
InvalidGetitem()[5] #@
InvalidGetitem2()[10] #@
"""
)
for node in ast_nodes[:3]:
self.assertRaises(InferenceError, next, node.infer())
for node in ast_nodes[3:]:
self.assertEqual(next(node.infer()), util.Uninferable)
ast_nodes = extract_node(
"""
[1, 2, 3][None] #@
'lala'['bala'] #@
"""
Expand Down

0 comments on commit 826d0e9

Please sign in to comment.