From 6bbd339901c219edec1debb47cd13a773054b5be Mon Sep 17 00:00:00 2001 From: cpopa Date: Wed, 30 Apr 2014 11:37:54 +0300 Subject: Simplify the lookup for the metaclass; add comments for the YES node tests. --- scoped_nodes.py | 10 ++++------ test/unittest_python3.py | 1 + test/unittest_scoped_nodes.py | 1 + 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scoped_nodes.py b/scoped_nodes.py index 067f01f..20bb664 100644 --- a/scoped_nodes.py +++ b/scoped_nodes.py @@ -1055,12 +1055,10 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin): if self._metaclass: # Expects this from Py3k TreeRebuilder try: - infered = next(self._metaclass.infer()) - except InferenceError: - return - if infered is YES: # don't expose it - return None - return infered + return next(node for node in self._metaclass.infer() + if node is not YES) + except (InferenceError, StopIteration): + return try: meta = self.getattr('__metaclass__')[0] diff --git a/test/unittest_python3.py b/test/unittest_python3.py index 9e80406..114e3d3 100644 --- a/test/unittest_python3.py +++ b/test/unittest_python3.py @@ -133,6 +133,7 @@ class Python3TC(TestCase): @require_version('3.0') def test_metaclass_yes_leak(self): astroid = self.builder.string_build(dedent(""" + # notice `ab` instead of `abc` from ab import ABCMeta class Meta(metaclass=ABCMeta): pass diff --git a/test/unittest_scoped_nodes.py b/test/unittest_scoped_nodes.py index 3d05318..6c56c55 100644 --- a/test/unittest_scoped_nodes.py +++ b/test/unittest_scoped_nodes.py @@ -718,6 +718,7 @@ def g2(): def test_metaclass_yes_leak(self): astroid = abuilder.string_build(dedent(""" + # notice `ab` instead of `abc` from ab import ABCMeta class Meta(object): -- cgit v1.2.1