diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-31 21:31:36 +0200 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-31 21:31:36 +0200 |
commit | 7a17ba37ce7a52fc82069814507c9fb65787368b (patch) | |
tree | 59ce1a64b8cb458892a33a0684e78a8bdbd06d0d /astroid/arguments.py | |
parent | 6193b56b752c81a011419feb026f8fd5d22d8163 (diff) | |
download | astroid-git-7a17ba37ce7a52fc82069814507c9fb65787368b.tar.gz |
Fix some inconsistencies with accessing the first argument of methods
If the current class is a metaclass (inherits from `type`), then
the first argument is always a class, not an instance.
Diffstat (limited to 'astroid/arguments.py')
-rw-r--r-- | astroid/arguments.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/astroid/arguments.py b/astroid/arguments.py index 5670fa86..e80f5f40 100644 --- a/astroid/arguments.py +++ b/astroid/arguments.py @@ -183,6 +183,16 @@ class CallSite(object): else: # XXX can do better ? boundnode = funcnode.parent.frame() + + if isinstance(boundnode, nodes.ClassDef): + # Verify that we're accessing a method + # of the metaclass through a class, as in + # `cls.metaclass_method`. In this case, the + # first argument is always the class. + method_scope = funcnode.parent.scope() + if method_scope is boundnode.metaclass(): + return iter((boundnode, )) + if funcnode.type == 'method': if not isinstance(boundnode, bases.Instance): boundnode = bases.Instance(boundnode) |