summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpopa <devnull@localhost>2013-12-18 17:29:05 +0200
committercpopa <devnull@localhost>2013-12-18 17:29:05 +0200
commit8a2d44f7ddb895a989901663200e64536a61b6e3 (patch)
tree7a0c2118df8219cd20addefbb5e05c9b4385bb6f
parent2dcc7c4448d5db3b0910c18eb35cb4118348e91b (diff)
downloadastroid-8a2d44f7ddb895a989901663200e64536a61b6e3.tar.gz
Add Changelog entry regarding `metaclass`, add a new test for py3k.
-rw-r--r--ChangeLog4
-rw-r--r--scoped_nodes.py2
-rw-r--r--test/unittest_python3.py13
3 files changed, 17 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 4df1b16..8a56ba8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@ Change log for the astroid package (used to be astng)
=====================================================
--
+ * Add `metaclass` function to `Class` nodes,
+ for retrieving the metaclass of a class node, working
+ for py3k as well.
+
* Add support for inferring arguments to namedtuple invocations.
* Make sure that objects returned for namedtuple
diff --git a/scoped_nodes.py b/scoped_nodes.py
index b6ec0a8..4ac1bd4 100644
--- a/scoped_nodes.py
+++ b/scoped_nodes.py
@@ -997,7 +997,7 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
if self._metaclass:
# Expects this from Py3k TreeRebuilder
try:
- return self._metaclass.infered()[0]
+ return next(self._metaclass.infer())
except InferenceError:
return
diff --git a/test/unittest_python3.py b/test/unittest_python3.py
index 0102c32..d17b143 100644
--- a/test/unittest_python3.py
+++ b/test/unittest_python3.py
@@ -79,7 +79,18 @@ class Python3TC(TestCase):
self.assertEqual(klass.as_string(),
'\n\nclass Test(metaclass=ABCMeta):\n pass\n')
-
+ @require_version('3.0')
+ def test_old_syntax_works(self):
+ astroid = self.builder.string_build(dedent("""
+ class Test:
+ __metaclass__ = type
+ class SubTest(Test): pass
+ """))
+ klass = astroid['SubTest']
+ metaclass = klass.metaclass()
+ self.assertIsInstance(metaclass, Class)
+ self.assertEqual(metaclass.name, 'type')
+
if __name__ == '__main__':
unittest_main()