summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorDavid Liu <david@cs.toronto.edu>2021-08-26 23:24:47 -0400
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-08-28 09:24:30 +0200
commit7824a2c3ad5bf8971668db23c3a6cd4e2c28bbc2 (patch)
tree73fe100388b94d637489d3fd19b98b0ca38125a8 /astroid
parentc7666b4ac0f476b98c50ad117256199993fa7f6c (diff)
downloadastroid-git-7824a2c3ad5bf8971668db23c3a6cd4e2c28bbc2.tar.gz
Fixed inference bug with unbound inherited methods
Diffstat (limited to 'astroid')
-rw-r--r--astroid/arguments.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/astroid/arguments.py b/astroid/arguments.py
index 3ee77ef9..a1104e2b 100644
--- a/astroid/arguments.py
+++ b/astroid/arguments.py
@@ -216,11 +216,15 @@ class CallSite:
positional.append(arg)
if argindex is not None:
+ boundnode = getattr(context, "boundnode", None)
# 2. first argument of instance/class method
if argindex == 0 and funcnode.type in ("method", "classmethod"):
- if context.boundnode is not None:
- boundnode = context.boundnode
- else:
+ # context.boundnode is None when an instance method is called with
+ # the class, e.g. MyClass.method(obj, ...). In this case, self
+ # is the first argument.
+ if boundnode is None and funcnode.type == "method" and positional:
+ return positional[0].infer(context=context)
+ if boundnode is None:
# XXX can do better ?
boundnode = funcnode.parent.frame()
@@ -242,7 +246,7 @@ class CallSite:
# if we have a method, extract one position
# from the index, so we'll take in account
# the extra parameter represented by `self` or `cls`
- if funcnode.type in ("method", "classmethod"):
+ if funcnode.type in ("method", "classmethod") and boundnode:
argindex -= 1
# 2. search arg index
try: