summaryrefslogtreecommitdiff
path: root/astroid/bases.py
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-04-24 14:47:22 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-04-24 15:15:41 +0200
commitf16b535a25ca9f1253fe608d0e59db42c7d89a62 (patch)
treef041d5bc51a0e126aac83faca69e3690b5f509c2 /astroid/bases.py
parent04d2c3ddd9d991d60211d22e8bb7e56caf5befa7 (diff)
downloadastroid-git-fix-self-inflicted-circular-import.tar.gz
Fix a strange construct that seem unnecessaryfix-self-inflicted-circular-import
And probably contribute to the circular import problem.
Diffstat (limited to 'astroid/bases.py')
-rw-r--r--astroid/bases.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/astroid/bases.py b/astroid/bases.py
index 05c0ae1c..0888f063 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -283,6 +283,23 @@ class Instance(BaseInstance):
except exceptions.AttributeInferenceError:
return False
+ def getitem(self, index, context=None):
+ # TODO: Rewrap index to Const for this case
+ new_context = contextmod.bind_context_to_node(context, self)
+ if not context:
+ context = new_context
+
+ # Create a new callcontext for providing index as an argument.
+ new_context.callcontext = contextmod.CallContext(args=[index])
+
+ method = next(self.igetattr("__getitem__", context=context), None)
+ if not isinstance(method, BoundMethod):
+ raise exceptions.InferenceError(
+ "Could not find __getitem__ for {node!r}.", node=self, context=context
+ )
+
+ return next(method.infer_call_result(self, new_context))
+
def pytype(self):
return self._proxied.qname()
@@ -316,10 +333,6 @@ class Instance(BaseInstance):
return True
return result
- # This is set in inference.py.
- def getitem(self, index, context=None):
- pass
-
class UnboundMethod(Proxy):
"""a special node representing a method not bound to an instance"""