summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2015-08-04 20:12:50 +0300
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2015-08-04 20:12:50 +0300
commitf10d081fe181a91b94c68ac9243e47c541093ad9 (patch)
tree7820d4ee8d66f592970da9a1e3b2b5deaa6a6597
parent73fcadd6831038f4e0f4bbc069c9f07115632024 (diff)
downloadastroid-f10d081fe181a91b94c68ac9243e47c541093ad9.tar.gz
Class._explicit_metaclass is now a public API, in the form of Class.declared_metaclass.
Class.mro remains the de facto method for retrieving the metaclass of a class, which will also do an evaluation of what declared_metaclass returns.
-rw-r--r--ChangeLog8
-rw-r--r--astroid/scoped_nodes.py13
2 files changed, 13 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index fcf5b09..dc5445e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -270,7 +270,13 @@ Change log for the astroid package (used to be astng)
AstroidBuilder._data_build.
Closes issue #116.
-
+
+ * Class._explicit_metaclass is now a public API, in the form of
+ Class.declared_metaclass.
+
+ Class.mro remains the de facto method for retrieving the metaclass
+ of a class, which will also do an evaluation of what declared_metaclass
+ returns.
2015-03-14 -- 1.3.6
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index 5a32e27..2a36ebd 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -990,7 +990,7 @@ class Class(bases.Statement, LocalsDictNodeNG, mixins.FilterStmtsMixin):
if base._newstyle_impl(context):
self._newstyle = True
break
- klass = self._explicit_metaclass()
+ klass = self.declared_metaclass()
# could be any callable, we'd need to infer the result of klass(name,
# bases, dict). punt if it's not a class node.
if klass is not None and isinstance(klass, Class):
@@ -1385,11 +1385,10 @@ class Class(bases.Statement, LocalsDictNodeNG, mixins.FilterStmtsMixin):
return builtin_lookup('type')[1][0]
_metaclass = None
- def _explicit_metaclass(self):
- """ Return the explicit defined metaclass
- for the current class.
+ def declared_metaclass(self):
+ """Return the explicit declared metaclass for the current class.
- An explicit defined metaclass is defined
+ An explicit declared metaclass is defined
either by passing the ``metaclass`` keyword argument
in the class definition line (Python 3) or (Python 2) by
having a ``__metaclass__`` class attribute, or if there are
@@ -1437,13 +1436,13 @@ class Class(bases.Statement, LocalsDictNodeNG, mixins.FilterStmtsMixin):
return infered
def metaclass(self):
- """ Return the metaclass of this class.
+ """Return the metaclass of this class.
If this class does not define explicitly a metaclass,
then the first defined metaclass in ancestors will be used
instead.
"""
- klass = self._explicit_metaclass()
+ klass = self.declared_metaclass()
if klass is None:
for parent in self.ancestors():
klass = parent.metaclass()