[Python-modules-commits] [astroid] 01/05: Import astroid_1.4.5.orig.tar.gz

Sandro Tosi morph at moszumanska.debian.org
Sat Apr 23 00:17:52 UTC 2016


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository astroid.

commit b022987c7b522ff79f3b73511cf7293619b1df9b
Author: Sandro Tosi <morph at debian.org>
Date:   Sat Apr 23 01:13:40 2016 +0100

    Import astroid_1.4.5.orig.tar.gz
---
 ChangeLog                              | 18 ++++++++++++++++++
 PKG-INFO                               |  2 +-
 astroid.egg-info/PKG-INFO              |  2 +-
 astroid/__pkginfo__.py                 |  2 +-
 astroid/builder.py                     |  2 +-
 astroid/inference.py                   | 12 ++++++------
 astroid/protocols.py                   | 19 ++++++++++++-------
 astroid/scoped_nodes.py                | 11 +++++++++--
 astroid/tests/unittest_regrtest.py     | 31 ++++++++++++++++++++++++++++++-
 astroid/tests/unittest_scoped_nodes.py | 28 +++++++++++++++++++++++++---
 setup.cfg                              |  4 ++--
 11 files changed, 106 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 759b6c1..1db8185 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,24 @@
 Change log for the astroid package (used to be astng)
 =====================================================
 
+2016-03-21 -- 1.4.5
+
+    * decoratornames() does not leak InferenceError anymore.
+
+    * wildcard_imported_names() got replaced by _public_names()
+
+      Our understanding of wildcard imports through __all__ was
+      half baked to say at least, since we couldn't account for
+      modifications of the list, which results in tons of false positives.
+      Instead, we replaced it with _public_names(), a method which returns
+      all the names that are publicly available in a module, that is that
+      don't start with an underscore, even though this means that there
+      is a possibility for other names to be leaked out even though
+      they are not present in the __all__ variable.
+
+      The method is private in 1.4.X.
+
+
 2016-01-15 -- 1.4.4
 
     * unpack_infer raises InferenceError if it can't operate
diff --git a/PKG-INFO b/PKG-INFO
index 7deb7e3..8462eeb 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: astroid
-Version: 1.4.4
+Version: 1.4.5
 Summary: A abstract syntax tree for Python with inference support.
 Home-page: http://bitbucket.org/logilab/astroid
 Author: Logilab
diff --git a/astroid.egg-info/PKG-INFO b/astroid.egg-info/PKG-INFO
index 7deb7e3..8462eeb 100644
--- a/astroid.egg-info/PKG-INFO
+++ b/astroid.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: astroid
-Version: 1.4.4
+Version: 1.4.5
 Summary: A abstract syntax tree for Python with inference support.
 Home-page: http://bitbucket.org/logilab/astroid
 Author: Logilab
diff --git a/astroid/__pkginfo__.py b/astroid/__pkginfo__.py
index 87f5c6d..2753060 100644
--- a/astroid/__pkginfo__.py
+++ b/astroid/__pkginfo__.py
@@ -20,7 +20,7 @@ distname = 'astroid'
 
 modname = 'astroid'
 
-numversion = (1, 4, 4)
+numversion = (1, 4, 5)
 version = '.'.join([str(num) for num in numversion])
 
 install_requires = ['six', 'lazy_object_proxy', 'wrapt']
diff --git a/astroid/builder.py b/astroid/builder.py
index 4a9c356..63c156a 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -202,7 +202,7 @@ class AstroidBuilder(raw_building.InspectBuilder):
                     imported = node.do_import_module()
                 except exceptions.InferenceError:
                     continue
-                for name in imported.wildcard_import_names():
+                for name in imported._public_names():
                     node.parent.set_local(name, node)
                     sort_locals(node.parent.scope()._locals[name])
             else:
diff --git a/astroid/inference.py b/astroid/inference.py
index 456a0f8..ddd4356 100644
--- a/astroid/inference.py
+++ b/astroid/inference.py
@@ -247,12 +247,12 @@ def infer_unaryop(self, context=None):
                     yield util.YES
 nodes.UnaryOp._infer = bases.path_wrapper(infer_unaryop)
 
-def _infer_binop(operator, operand1, operand2, context, failures=None):
+def _infer_binop(binop, operand1, operand2, context, failures=None):
     if operand1 is util.YES:
         yield operand1
         return
     try:
-        for valnode in operand1.infer_binary_op(operator, operand2, context):
+        for valnode in operand1.infer_binary_op(binop, operand2, context):
             yield valnode
     except AttributeError:
         try:
@@ -270,11 +270,11 @@ def _infer_binop(operator, operand1, operand2, context, failures=None):
 def infer_binop(self, context=None):
     failures = []
     for lhs in self.left.infer(context):
-        for val in _infer_binop(self.op, lhs, self.right, context, failures):
+        for val in _infer_binop(self, lhs, self.right, context, failures):
             yield val
     for lhs in failures:
         for rhs in self.right.infer(context):
-            for val in _infer_binop(self.op, rhs, lhs, context):
+            for val in _infer_binop(self, rhs, lhs, context):
                 yield val
 nodes.BinOp._infer = bases.path_wrapper(infer_binop)
 
@@ -304,11 +304,11 @@ nodes.AssignAttr._infer = infer_assign
 def infer_augassign(self, context=None):
     failures = []
     for lhs in self.target.infer_lhs(context):
-        for val in _infer_binop(self.op, lhs, self.value, context, failures):
+        for val in _infer_binop(self, lhs, self.value, context, failures):
             yield val
     for lhs in failures:
         for rhs in self.value.infer(context):
-            for val in _infer_binop(self.op, rhs, lhs, context):
+            for val in _infer_binop(self, rhs, lhs, context):
                 yield val
 nodes.AugAssign._infer = bases.path_wrapper(infer_augassign)
 
diff --git a/astroid/protocols.py b/astroid/protocols.py
index 6f15998..87a6d4d 100644
--- a/astroid/protocols.py
+++ b/astroid/protocols.py
@@ -103,7 +103,8 @@ if sys.version_info >= (3, 5):
 for key, impl in list(BIN_OP_IMPL.items()):
     BIN_OP_IMPL[key+'='] = impl
 
-def const_infer_binary_op(self, operator, other, context):
+def const_infer_binary_op(self, binop, other, context):
+    operator = binop.op
     for other in other.infer(context):
         if isinstance(other, nodes.Const):
             try:
@@ -122,7 +123,7 @@ def const_infer_binary_op(self, operator, other, context):
             yield other
         else:
             try:
-                for val in other.infer_binary_op(operator, self, context):
+                for val in other.infer_binary_op(binop, self, context):
                     yield val
             except AttributeError:
                 yield util.YES
@@ -130,8 +131,9 @@ nodes.Const.infer_binary_op = bases.yes_if_nothing_inferred(const_infer_binary_o
 
 
 
-def _multiply_seq_by_int(self, other, context):
+def _multiply_seq_by_int(self, binop, other, context):
     node = self.__class__()
+    node.parent = binop
     elts = []
     for elt in self.elts:
         infered = util.safe_infer(elt, context)
@@ -151,10 +153,12 @@ def _filter_uninferable_nodes(elts, context):
                 yield inferred
 
 
-def tl_infer_binary_op(self, operator, other, context):
+def tl_infer_binary_op(self, binop, other, context):
+    operator = binop.op
     for other in other.infer(context):
         if isinstance(other, self.__class__) and operator == '+':
             node = self.__class__()
+            node.parent = binop
             elts = list(_filter_uninferable_nodes(self.elts, context))
             elts += list(_filter_uninferable_nodes(other.elts, context))
             node.elts = elts
@@ -163,7 +167,7 @@ def tl_infer_binary_op(self, operator, other, context):
             if not isinstance(other.value, int):
                 yield util.YES
                 continue
-            yield _multiply_seq_by_int(self, other, context)
+            yield _multiply_seq_by_int(self, binop, other, context)
         elif isinstance(other, bases.Instance) and not isinstance(other, nodes.Const):
             yield util.YES
     # XXX else log TypeError
@@ -171,14 +175,15 @@ nodes.Tuple.infer_binary_op = bases.yes_if_nothing_inferred(tl_infer_binary_op)
 nodes.List.infer_binary_op = bases.yes_if_nothing_inferred(tl_infer_binary_op)
 
 
-def dict_infer_binary_op(self, operator, other, context):
+def dict_infer_binary_op(self, binop, other, context):
     for other in other.infer(context):
         if isinstance(other, bases.Instance) and isinstance(other._proxied, nodes.ClassDef):
             yield util.YES
         # XXX else log TypeError
 nodes.Dict.infer_binary_op = bases.yes_if_nothing_inferred(dict_infer_binary_op)
 
-def instance_infer_binary_op(self, operator, other, context):
+def instance_infer_binary_op(self, binop, other, context):
+    operator = binop.op
     try:
         methods = self.getattr(BIN_OP_METHOD[operator])
     except (exceptions.NotFoundError, KeyError):
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index c0b0179..2a23f0b 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -568,6 +568,10 @@ class Module(LocalsDictNodeNG):
                     inferred.append(inferred_node.value)
         return inferred
 
+    def _public_names(self):
+        """Get the list of the names which are publicly available in this module."""
+        return [name for name in self.keys() if not name.startswith('_')]
+
     def bool_value(self):
         return True
 
@@ -887,8 +891,11 @@ class FunctionDef(bases.Statement, Lambda):
             decoratornodes += self.decorators.nodes
         decoratornodes += self.extra_decorators
         for decnode in decoratornodes:
-            for infnode in decnode.infer():
-                result.add(infnode.qname())
+            try:
+                for infnode in decnode.infer():
+                    result.add(infnode.qname())
+            except exceptions.InferenceError:
+                continue
         return result
 
     def is_bound(self):
diff --git a/astroid/tests/unittest_regrtest.py b/astroid/tests/unittest_regrtest.py
index 181c60c..608426b 100644
--- a/astroid/tests/unittest_regrtest.py
+++ b/astroid/tests/unittest_regrtest.py
@@ -149,7 +149,7 @@ multiply(1, 2, 3)
         astroid = builder.string_build(data, __name__, __file__)
         callfunc = astroid.body[1].value.func
         inferred = callfunc.inferred()
-        self.assertEqual(len(inferred), 1)
+        self.assertEqual(len(inferred), 2)
 
     @require_version('3.0')
     def test_nameconstant(self):
@@ -299,6 +299,35 @@ def test():
 
         next(node.value.infer()).as_string()
 
+    def test_binop_generates_nodes_with_parents(self):
+        node = extract_node('''
+        def no_op(*args):
+            pass
+        def foo(*args):
+            def inner(*more_args):
+                args + more_args #@
+            return inner
+        ''')
+        inferred = next(node.infer())
+        self.assertIsInstance(inferred, nodes.Tuple)
+        self.assertIsNotNone(inferred.parent)
+        self.assertIsInstance(inferred.parent, nodes.BinOp)
+
+    def test_decorator_names_inference_error_leaking(self):
+        node = extract_node('''
+        class Parent(object):
+            @property
+            def foo(self):
+                pass
+
+        class Child(Parent):
+            @Parent.foo.getter
+            def foo(self): #@
+                return super(Child, self).foo + ['oink']
+        ''')
+        inferred = next(node.infer())
+        self.assertEqual(inferred.decoratornames(), set())
+
 
 class Whatever(object):
     a = property(lambda x: x, lambda x: x)
diff --git a/astroid/tests/unittest_scoped_nodes.py b/astroid/tests/unittest_scoped_nodes.py
index 9a7c99a..0019ee0 100644
--- a/astroid/tests/unittest_scoped_nodes.py
+++ b/astroid/tests/unittest_scoped_nodes.py
@@ -111,19 +111,41 @@ class ModuleNodeTest(ModuleLoader, unittest.TestCase):
         res = sorted(m.wildcard_import_names())
         self.assertEqual(res, ['Aaa', 'func', 'name', 'other'])
 
+    def test_public_names(self):
+        m = builder.parse('''
+        name = 'a'
+        _bla = 2
+        other = 'o'
+        class Aaa: pass
+        def func(): print('yo')
+        __all__ = 'Aaa', '_bla', 'name'
+        ''')
+        values = sorted(['Aaa', 'name', 'other', 'func'])
+        self.assertEqual(sorted(m._public_names()), values)
+        m = builder.parse('''
+        name = 'a'
+        _bla = 2
+        other = 'o'
+        class Aaa: pass
+
+        def func(): return 'yo'
+        ''')
+        res = sorted(m._public_names())
+        self.assertEqual(res, values)
+
         m = builder.parse('''
             from missing import tzop
             trop = "test"
             __all__ = (trop, "test1", tzop, 42)
         ''')
-        res = sorted(m.wildcard_import_names())
-        self.assertEqual(res, ["test", "test1"])
+        res = sorted(m._public_names())
+        self.assertEqual(res, ["trop", "tzop"])
 
         m = builder.parse('''
             test = tzop = 42
             __all__ = ('test', ) + ('tzop', )
         ''')
-        res = sorted(m.wildcard_import_names())
+        res = sorted(m._public_names())
         self.assertEqual(res, ['test', 'tzop'])
 
     def test_module_getattr(self):
diff --git a/setup.cfg b/setup.cfg
index 3f8d96b..caf8563 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -2,7 +2,7 @@
 universal = 1
 
 [egg_info]
-tag_build = 
-tag_svn_revision = 0
 tag_date = 0
+tag_svn_revision = 0
+tag_build = 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/astroid.git



More information about the Python-modules-commits mailing list