Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
* Change Instance.getitem to return all inference results
  pylint-dev#960
  • Loading branch information
cdce8p committed May 13, 2021
1 parent 15e1921 commit ab1d559
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion astroid/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def getitem(self, index, context=None):
raise exceptions.InferenceError(
"Could not find __getitem__ for {node!r}.", node=self, context=context
)
return next(method.infer_call_result(self, new_context))
return list(method.infer_call_result(self, new_context))


class UnboundMethod(Proxy):
Expand Down
7 changes: 5 additions & 2 deletions astroid/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,15 @@ def infer_subscript(self, context=None):
) as exc:
raise exceptions.InferenceError(node=self, context=context) from exc

if not isinstance(assigned, list):
assigned = [assigned]
# Prevent inferring if the inferred subscript
# is the same as the original subscripted object.
if self is assigned or assigned is util.Uninferable:
if self in assigned or util.Uninferable in assigned:
yield util.Uninferable
return None
yield from assigned.infer(context)
for elm in assigned:
yield from elm.infer(context)
found_one = True

if found_one:
Expand Down

0 comments on commit ab1d559

Please sign in to comment.