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

Sandro Tosi morph at moszumanska.debian.org
Mon Dec 25 05:29:40 UTC 2017


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

morph pushed a commit to branch master
in repository astroid.

commit 860fc3d17ff5e18f38af8f2a5cbe114f4268b8e4
Author: Sandro Tosi <morph at debian.org>
Date:   Mon Dec 25 00:19:59 2017 -0500

    Import astroid_1.6.0.orig.tar.gz
---
 ChangeLog                                |   60 +-
 PKG-INFO                                 |   14 +-
 README.rst                               |    2 +-
 astroid.egg-info/PKG-INFO                |   14 +-
 astroid.egg-info/SOURCES.txt             |    4 +
 astroid.egg-info/requires.txt            |    4 +-
 astroid/__pkginfo__.py                   |   19 +-
 astroid/astpeephole.py                   |   10 +-
 astroid/bases.py                         |   18 +-
 astroid/brain/brain_attrs.py             |   52 +
 astroid/brain/brain_builtin_inference.py |   23 +
 astroid/brain/brain_collections.py       |   33 +-
 astroid/brain/brain_curses.py            |  177 +++
 astroid/brain/brain_fstrings.py          |    3 +-
 astroid/brain/brain_namedtuple_enum.py   |  116 +-
 astroid/brain/brain_numpy.py             |  163 +-
 astroid/brain/brain_subprocess.py        |    4 +-
 astroid/brain/brain_uuid.py              |   22 +
 astroid/builder.py                       |    1 +
 astroid/exceptions.py                    |    6 -
 astroid/helpers.py                       |    7 +-
 astroid/inference.py                     |    9 +-
 astroid/interpreter/_import/spec.py      |    5 +-
 astroid/interpreter/objectmodel.py       |    1 -
 astroid/modutils.py                      |    2 +
 astroid/node_classes.py                  | 2493 ++++++++++++++++++++++++++++--
 astroid/nodes.py                         |   20 +-
 astroid/protocols.py                     |    4 +-
 astroid/raw_building.py                  |    1 +
 astroid/rebuilder.py                     |    8 +-
 astroid/scoped_nodes.py                  | 1158 ++++++++++++--
 astroid/tests/unittest_brain.py          |  167 +-
 astroid/tests/unittest_brain_numpy.py    |  242 +++
 astroid/tests/unittest_builder.py        |    4 +-
 astroid/tests/unittest_inference.py      |   38 +
 astroid/tests/unittest_manager.py        |   23 +-
 astroid/tests/unittest_nodes.py          |    6 +
 astroid/tests/unittest_protocols.py      |   24 +
 astroid/tests/unittest_python3.py        |   32 +-
 astroid/tests/unittest_scoped_nodes.py   |   95 +-
 astroid/tests/unittest_transforms.py     |    1 +
 astroid/util.py                          |   24 +-
 setup.py                                 |    1 +
 tox.ini                                  |   13 +-
 44 files changed, 4604 insertions(+), 519 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7440194..7b2bd96 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,64 @@
 Change log for the astroid package (used to be astng)
 =====================================================
 
+2017-12-15 -- 1.6.0
+
+   * When verifying duplicates classes in MRO, ignore on-the-fly generated classes
+
+     Close PyCQA/pylint#1706
+
+   * Add brain tip for attrs library to prevent unsupported-assignment-operation false positives
+
+	 Close PYCQA/pylint#1698
+
+   * file_stream was removed, since it was deprecated for three releases
+
+     Instead one should use the .stream() method.
+
+   * Vast improvements to numpy support
+
+   * Add brain tips for curses
+
+     Close PyCQA/pylint#1703
+
+   * Add brain tips for UUID.int
+
+     Close PyCQA/pylint#961
+
+   * The result of using object.__new__ as class decorator is correctly inferred as instance
+
+     Close #172
+
+   * Enums created with functional syntax are now iterable
+
+   * Enums created with functional syntax are now subscriptable
+
+   * Don't crash when getting the string representation of BadUnaryOperationMessage
+
+     In some cases, when the operand does not have a .name attribute,
+     getting the string representation of a BadUnaryOperationMessage leads
+     to a crash.
+
+     Close PyCQA/pylint#1563
+
+   * Don't raise DuplicateBaseError when classes at different locations are used
+
+     For instance, one can implement a namedtuple base class, which gets reused
+     on a class with the same name later on in the file. Until now, we considered
+     these two classes as being the same, because they shared the name, but in fact
+     they are different, being created at different locations and through different
+     means.
+
+     Close PyCQA/pylint#1458
+
+    * The func form of namedtuples with keywords is now understood
+
+      Close PyCQA/pylint#1530
+
+    * Dunder class at method level is now inferred as the class of the method
+
+      Close PyCQA/pylint#1328
+
 2017-06-03 -- 1.5.3
 
     * enum34 dependency is forced to be at least version 1.1.3. Fixes spurious
@@ -1006,7 +1064,7 @@ Change log for the astroid package (used to be astng)
 
 
 2010-03-22  --  0.20.0
-    * fix #20464: raises “TypeError: '_Yes' object is not iterable” on list inference
+    * fix #20464: raises ?TypeError: '_Yes' object is not iterable? on list inference
 
     * fix #19882: pylint hangs
 
diff --git a/PKG-INFO b/PKG-INFO
index d39ac04..b0c27e1 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,11 +1,12 @@
-Metadata-Version: 1.1
+Metadata-Version: 1.2
 Name: astroid
-Version: 1.5.3
+Version: 1.6.0
 Summary: A abstract syntax tree for Python with inference support.
 Home-page: https://github.com/PyCQA/astroid
 Author: Python Code Quality Authority
 Author-email: code-quality at python.org
 License: LGPL
+Description-Content-Type: UNKNOWN
 Description: Astroid
         =======
         
@@ -63,7 +64,7 @@ Description: Astroid
         Python Versions
         ---------------
         
-        astroid is compatible with Python 2.7 as well as 3.3 and later. astroid uses
+        astroid is compatible with Python 2.7 as well as 3.4 and later. astroid uses
         the same code base for both Python versions, using six.
         
         Test
@@ -79,4 +80,11 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
 Classifier: Topic :: Software Development :: Quality Assurance
 Classifier: Programming Language :: Python
 Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.7
 Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Programming Language :: Python :: Implementation :: PyPy
+Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
diff --git a/README.rst b/README.rst
index 5e2f629..7cd5571 100644
--- a/README.rst
+++ b/README.rst
@@ -55,7 +55,7 @@ http://lists.logilab.org/mailman/listinfo/python-projects .
 Python Versions
 ---------------
 
-astroid is compatible with Python 2.7 as well as 3.3 and later. astroid uses
+astroid is compatible with Python 2.7 as well as 3.4 and later. astroid uses
 the same code base for both Python versions, using six.
 
 Test
diff --git a/astroid.egg-info/PKG-INFO b/astroid.egg-info/PKG-INFO
index d39ac04..b0c27e1 100644
--- a/astroid.egg-info/PKG-INFO
+++ b/astroid.egg-info/PKG-INFO
@@ -1,11 +1,12 @@
-Metadata-Version: 1.1
+Metadata-Version: 1.2
 Name: astroid
-Version: 1.5.3
+Version: 1.6.0
 Summary: A abstract syntax tree for Python with inference support.
 Home-page: https://github.com/PyCQA/astroid
 Author: Python Code Quality Authority
 Author-email: code-quality at python.org
 License: LGPL
+Description-Content-Type: UNKNOWN
 Description: Astroid
         =======
         
@@ -63,7 +64,7 @@ Description: Astroid
         Python Versions
         ---------------
         
-        astroid is compatible with Python 2.7 as well as 3.3 and later. astroid uses
+        astroid is compatible with Python 2.7 as well as 3.4 and later. astroid uses
         the same code base for both Python versions, using six.
         
         Test
@@ -79,4 +80,11 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
 Classifier: Topic :: Software Development :: Quality Assurance
 Classifier: Programming Language :: Python
 Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 2.7
 Classifier: Programming Language :: Python :: 3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
+Classifier: Programming Language :: Python :: Implementation :: CPython
+Classifier: Programming Language :: Python :: Implementation :: PyPy
+Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
diff --git a/astroid.egg-info/SOURCES.txt b/astroid.egg-info/SOURCES.txt
index b9ea18a..293843b 100644
--- a/astroid.egg-info/SOURCES.txt
+++ b/astroid.egg-info/SOURCES.txt
@@ -36,8 +36,10 @@ astroid.egg-info/SOURCES.txt
 astroid.egg-info/dependency_links.txt
 astroid.egg-info/requires.txt
 astroid.egg-info/top_level.txt
+astroid/brain/brain_attrs.py
 astroid/brain/brain_builtin_inference.py
 astroid/brain/brain_collections.py
+astroid/brain/brain_curses.py
 astroid/brain/brain_dateutil.py
 astroid/brain/brain_fstrings.py
 astroid/brain/brain_functools.py
@@ -58,6 +60,7 @@ astroid/brain/brain_ssl.py
 astroid/brain/brain_subprocess.py
 astroid/brain/brain_threading.py
 astroid/brain/brain_typing.py
+astroid/brain/brain_uuid.py
 astroid/interpreter/__init__.py
 astroid/interpreter/dunder_lookup.py
 astroid/interpreter/objectmodel.py
@@ -67,6 +70,7 @@ astroid/interpreter/_import/util.py
 astroid/tests/__init__.py
 astroid/tests/resources.py
 astroid/tests/unittest_brain.py
+astroid/tests/unittest_brain_numpy.py
 astroid/tests/unittest_builder.py
 astroid/tests/unittest_helpers.py
 astroid/tests/unittest_inference.py
diff --git a/astroid.egg-info/requires.txt b/astroid.egg-info/requires.txt
index 51b577f..e356a8d 100644
--- a/astroid.egg-info/requires.txt
+++ b/astroid.egg-info/requires.txt
@@ -2,9 +2,7 @@ lazy_object_proxy
 six
 wrapt
 
-[:python_version<"3.3"]
-backports.functools_lru_cache
-
 [:python_version<"3.4"]
 enum34>=1.1.3
 singledispatch
+backports.functools_lru_cache
diff --git a/astroid/__pkginfo__.py b/astroid/__pkginfo__.py
index 96c2dcb..1aa41db 100644
--- a/astroid/__pkginfo__.py
+++ b/astroid/__pkginfo__.py
@@ -16,7 +16,7 @@ distname = 'astroid'
 
 modname = 'astroid'
 
-version = '1.5.3'
+version = '1.6.0'
 numversion = tuple(map(int, version.split('.')))
 
 extras_require = {}
@@ -34,13 +34,14 @@ def has_environment_marker_range_operators_support():
 
 
 if has_environment_marker_range_operators_support():
-    extras_require[':python_version<"3.4"'] = ['enum34>=1.1.3', 'singledispatch']
-    extras_require[':python_version<"3.3"'] = ['backports.functools_lru_cache']
+    extras_require[':python_version<"3.4"'] = ['enum34>=1.1.3',
+                                               'singledispatch',
+                                               'backports.functools_lru_cache']
 else:
     if py_version < (3, 4):
-        install_requires.extend(['enum34', 'singledispatch'])
-    if py_version < (3, 3):
-        install_requires.append('backports.functools_lru_cache')
+        install_requires.extend(['enum34',
+                                 'singledispatch',
+                                 'backports.functools_lru_cache'])
 
 
 # pylint: disable=redefined-builtin; why license is a builtin anyway?
@@ -57,5 +58,11 @@ classifiers = ["Topic :: Software Development :: Libraries :: Python Modules",
                "Topic :: Software Development :: Quality Assurance",
                "Programming Language :: Python",
                "Programming Language :: Python :: 2",
+               "Programming Language :: Python :: 2.7",
                "Programming Language :: Python :: 3",
+               "Programming Language :: Python :: 3.4",
+               "Programming Language :: Python :: 3.5",
+               "Programming Language :: Python :: 3.6",
+               "Programming Language :: Python :: Implementation :: CPython",
+               "Programming Language :: Python :: Implementation :: PyPy",
               ]
diff --git a/astroid/astpeephole.py b/astroid/astpeephole.py
index dde5dca..6e6ea7b 100644
--- a/astroid/astpeephole.py
+++ b/astroid/astpeephole.py
@@ -39,14 +39,14 @@ class ASTPeepholeOptimizer(object):
         while isinstance(current, _ast.BinOp):
             # lhs must be a BinOp with the addition operand.
             if not isinstance(current.left, _ast.BinOp):
-                return
+                return None
             if (not isinstance(current.left.op, _ast.Add)
                     or not isinstance(current.op, _ast.Add)):
-                return
+                return None
 
             # rhs must a str / bytes.
             if not isinstance(current.right, _TYPES):
-                return
+                return None
 
             ast_nodes.append(current.right.s)
             current = current.left
@@ -61,13 +61,13 @@ class ASTPeepholeOptimizer(object):
                 break
 
         if not ast_nodes:
-            return
+            return None
 
         # If we have inconsistent types, bail out.
         known = type(ast_nodes[0])
         if any(not isinstance(element, known)
                for element in ast_nodes[1:]):
-            return
+            return None
 
         value = known().join(reversed(ast_nodes))
         newnode = nodes.Const(value, node.lineno, node.col_offset, parent)
diff --git a/astroid/bases.py b/astroid/bases.py
index aefbaa1..3b6a248 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -341,47 +341,47 @@ class BoundMethod(UnboundMethod):
         mcs = next(caller.args[0].infer(context=context))
         if mcs.__class__.__name__ != 'ClassDef':
             # Not a valid first argument.
-            return
+            return None
         if not mcs.is_subtype_of("%s.type" % BUILTINS):
             # Not a valid metaclass.
-            return
+            return None
 
         # Verify the name
         name = next(caller.args[1].infer(context=context))
         if name.__class__.__name__ != 'Const':
             # Not a valid name, needs to be a const.
-            return
+            return None
         if not isinstance(name.value, str):
             # Needs to be a string.
-            return
+            return None
 
         # Verify the bases
         bases = next(caller.args[2].infer(context=context))
         if bases.__class__.__name__ != 'Tuple':
             # Needs to be a tuple.
-            return
+            return None
         inferred_bases = [next(elt.infer(context=context))
                           for elt in bases.elts]
         if any(base.__class__.__name__ != 'ClassDef'
                for base in inferred_bases):
             # All the bases needs to be Classes
-            return
+            return None
 
         # Verify the attributes.
         attrs = next(caller.args[3].infer(context=context))
         if attrs.__class__.__name__ != 'Dict':
             # Needs to be a dictionary.
-            return
+            return None
         cls_locals = collections.defaultdict(list)
         for key, value in attrs.items:
             key = next(key.infer(context=context))
             value = next(value.infer(context=context))
             if key.__class__.__name__ != 'Const':
                 # Something invalid as an attribute.
-                return
+                return None
             if not isinstance(key.value, str):
                 # Not a proper attribute.
-                return
+                return None
             cls_locals[key.value].append(value)
 
         # Build the class from now.
diff --git a/astroid/brain/brain_attrs.py b/astroid/brain/brain_attrs.py
new file mode 100644
index 0000000..ed27e60
--- /dev/null
+++ b/astroid/brain/brain_attrs.py
@@ -0,0 +1,52 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+"""
+Astroid hook for the attrs library
+
+Without this hook pylint reports unsupported-assignment-operation
+for atrrs classes
+"""
+
+import astroid
+from astroid import MANAGER
+
+
+ATTR_IB = 'attr.ib'
+
+
+def is_decorated_with_attrs(
+        node, decorator_names=('attr.s', 'attr.attrs', 'attr.attributes')):
+    """Return True if a decorated node has
+    an attr decorator applied."""
+    if not node.decorators:
+        return False
+    for decorator_attribute in node.decorators.nodes:
+        if decorator_attribute.as_string() in decorator_names:
+            return True
+    return False
+
+
+def attr_attributes_transform(node):
+    """Given that the ClassNode has an attr decorator,
+    rewrite class attributes as instance attributes
+    """
+    for cdefbodynode in node.body:
+        if not isinstance(cdefbodynode, astroid.Assign):
+            continue
+        if isinstance(cdefbodynode.value, astroid.Call):
+            if cdefbodynode.value.func.as_string() != ATTR_IB:
+                continue
+        for target in cdefbodynode.targets:
+
+            rhs_node = astroid.Unknown(
+                lineno=cdefbodynode.lineno,
+                col_offset=cdefbodynode.col_offset,
+                parent=cdefbodynode
+            )
+            node.locals[target.name] = [rhs_node]
+
+
+MANAGER.register_transform(
+    astroid.Class,
+    attr_attributes_transform,
+    is_decorated_with_attrs)
diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py
index 717dc78..4286c75 100644
--- a/astroid/brain/brain_builtin_inference.py
+++ b/astroid/brain/brain_builtin_inference.py
@@ -21,6 +21,10 @@ from astroid import objects
 from astroid import scoped_nodes
 from astroid import util
 
+
+OBJECT_DUNDER_NEW = 'object.__new__'
+
+
 def _extend_str(class_node, rvalue):
     """function to extend builtin str/unicode class"""
     # TODO(cpopa): this approach will make astroid to believe
@@ -73,12 +77,14 @@ def _extend_str(class_node, rvalue):
         class_node.locals[method.name] = [method]
         method.parent = class_node
 
+
 def extend_builtins(class_transforms):
     from astroid.bases import BUILTINS
     builtin_ast = MANAGER.astroid_cache[BUILTINS]
     for class_name, transform in class_transforms.items():
         transform(builtin_ast[class_name])
 
+
 if sys.version_info > (3, 0):
     extend_builtins({'bytes': partial(_extend_str, rvalue="b''"),
                      'str': partial(_extend_str, rvalue="''")})
@@ -481,6 +487,17 @@ def infer_slice(node, context=None):
     return slice_node
 
 
+def _infer_object__new__decorator(node, context=None):
+    if not node.decorators:
+        raise UseInferenceDefault
+
+    for decorator in node.decorators.nodes:
+        if isinstance(decorator, nodes.Attribute):
+            if decorator.as_string() == OBJECT_DUNDER_NEW:
+                return iter((node.instantiate_class(),))
+    raise UseInferenceDefault
+
+
 # Builtins inference
 register_builtin_transform(infer_bool, 'bool')
 register_builtin_transform(infer_super, 'super')
@@ -494,3 +511,9 @@ register_builtin_transform(infer_dict, 'dict')
 register_builtin_transform(infer_frozenset, 'frozenset')
 register_builtin_transform(infer_type, 'type')
 register_builtin_transform(infer_slice, 'slice')
+
+# Infer object.__new__ calls
+MANAGER.register_transform(
+    nodes.ClassDef,
+    inference_tip(_infer_object__new__decorator)
+)
diff --git a/astroid/brain/brain_collections.py b/astroid/brain/brain_collections.py
index 7734337..1f286dd 100644
--- a/astroid/brain/brain_collections.py
+++ b/astroid/brain/brain_collections.py
@@ -2,9 +2,12 @@
 
 # Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
 # For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+import sys
 
 import astroid
 
+PY35 = sys.version_info >= (3, 5)
+
 
 def _collections_transform():
     return astroid.parse('''
@@ -13,6 +16,15 @@ def _collections_transform():
         def __missing__(self, key): pass
         def __getitem__(self, key): return default_factory
 
+    ''' + _deque_mock() + '''
+
+    class OrderedDict(dict):
+        def __reversed__(self): return self[::-1]
+    ''')
+
+
+def _deque_mock():
+    base_deque_class = '''
     class deque(object):
         maxlen = 0
         def __init__(self, iterable=None, maxlen=None):
@@ -33,11 +45,22 @@ def _collections_transform():
         def __getitem__(self, index): pass
         def __setitem__(self, index, value): pass
         def __delitem__(self, index): pass
-
-        def OrderedDict(dict):
-            def __reversed__(self): return self[::-1]
-    ''')
-
+        def __bool__(self): return bool(self.iterable)
+        def __nonzero__(self): return bool(self.iterable)
+        def __contains__(self, o): return o in self.iterable
+        def __len__(self): return len(self.iterable)
+        def __copy__(self): return deque(self.iterable)'''
+    if PY35:
+        base_deque_class += '''
+        def copy(self): return deque(self.iterable)
+        def index(self, x, start=0, end=0): return 0
+        def insert(self, x, i): pass
+        def __add__(self, other): pass
+        def __iadd__(self, other): pass
+        def __mul__(self, other): pass
+        def __imul__(self, other): pass
+        def __rmul__(self, other): pass'''
+    return base_deque_class
 
 astroid.register_module_extender(astroid.MANAGER, 'collections', _collections_transform)
 
diff --git a/astroid/brain/brain_curses.py b/astroid/brain/brain_curses.py
new file mode 100644
index 0000000..f195483
--- /dev/null
+++ b/astroid/brain/brain_curses.py
@@ -0,0 +1,177 @@
+# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
+# For details: https://github.com/PyCQA/astroid/blob/master/COPYING.LESSER
+import astroid
+
+
+def _curses_transform():
+    return astroid.parse('''
+    A_ALTCHARSET = 1
+    A_BLINK = 1
+    A_BOLD = 1
+    A_DIM = 1
+    A_INVIS = 1
+    A_ITALIC = 1
+    A_NORMAL = 1
+    A_PROTECT = 1
+    A_REVERSE = 1
+    A_STANDOUT = 1
+    A_UNDERLINE = 1
+    A_HORIZONTAL = 1
+    A_LEFT = 1
+    A_LOW = 1
+    A_RIGHT = 1
+    A_TOP = 1
+    A_VERTICAL = 1
+    A_CHARTEXT = 1
+    A_ATTRIBUTES = 1
+    A_CHARTEXT = 1
+    A_COLOR = 1
+    KEY_MIN = 1
+    KEY_BREAK = 1
+    KEY_DOWN = 1
+    KEY_UP = 1
+    KEY_LEFT = 1
+    KEY_RIGHT = 1
+    KEY_HOME = 1
+    KEY_BACKSPACE = 1
+    KEY_F0 = 1
+    KEY_Fn = 1
+    KEY_DL = 1
+    KEY_IL = 1
+    KEY_DC = 1
+    KEY_IC = 1
+    KEY_EIC = 1
+    KEY_CLEAR = 1
+    KEY_EOS = 1
+    KEY_EOL = 1
+    KEY_SF = 1
+    KEY_SR = 1
+    KEY_NPAGE = 1
+    KEY_PPAGE = 1
+    KEY_STAB = 1
+    KEY_CTAB = 1
+    KEY_CATAB = 1
+    KEY_ENTER = 1
+    KEY_SRESET = 1
+    KEY_RESET = 1
+    KEY_PRINT = 1
+    KEY_LL = 1
+    KEY_A1 = 1
+    KEY_A3 = 1
+    KEY_B2 = 1
+    KEY_C1 = 1
+    KEY_C3 = 1
+    KEY_BTAB = 1
+    KEY_BEG = 1
+    KEY_CANCEL = 1
+    KEY_CLOSE = 1
+    KEY_COMMAND = 1
+    KEY_COPY = 1
+    KEY_CREATE = 1
+    KEY_END = 1
+    KEY_EXIT = 1
+    KEY_FIND = 1
+    KEY_HELP = 1
+    KEY_MARK = 1
+    KEY_MESSAGE = 1
+    KEY_MOVE = 1
+    KEY_NEXT = 1
+    KEY_OPEN = 1
+    KEY_OPTIONS = 1
+    KEY_PREVIOUS = 1
+    KEY_REDO = 1
+    KEY_REFERENCE = 1
+    KEY_REFRESH = 1
+    KEY_REPLACE = 1
+    KEY_RESTART = 1
+    KEY_RESUME = 1
+    KEY_SAVE = 1
+    KEY_SBEG = 1
+    KEY_SCANCEL = 1
+    KEY_SCOMMAND = 1
+    KEY_SCOPY = 1
+    KEY_SCREATE = 1
+    KEY_SDC = 1
+    KEY_SDL = 1
+    KEY_SELECT = 1
+    KEY_SEND = 1
+    KEY_SEOL = 1
+    KEY_SEXIT = 1
+    KEY_SFIND = 1
+    KEY_SHELP = 1
+    KEY_SHOME = 1
+    KEY_SIC = 1
+    KEY_SLEFT = 1
+    KEY_SMESSAGE = 1
+    KEY_SMOVE = 1
+    KEY_SNEXT = 1
+    KEY_SOPTIONS = 1
+    KEY_SPREVIOUS = 1
+    KEY_SPRINT = 1
+    KEY_SREDO = 1
+    KEY_SREPLACE = 1
+    KEY_SRIGHT = 1
+    KEY_SRSUME = 1
+    KEY_SSAVE = 1
+    KEY_SSUSPEND = 1
+    KEY_SUNDO = 1
+    KEY_SUSPEND = 1
+    KEY_UNDO = 1
+    KEY_MOUSE = 1
+    KEY_RESIZE = 1
+    KEY_MAX = 1
+    ACS_BBSS = 1
+    ACS_BLOCK = 1
+    ACS_BOARD = 1
+    ACS_BSBS = 1
+    ACS_BSSB = 1
+    ACS_BSSS = 1
+    ACS_BTEE = 1
+    ACS_BULLET = 1
+    ACS_CKBOARD = 1
+    ACS_DARROW = 1
+    ACS_DEGREE = 1
+    ACS_DIAMOND = 1
+    ACS_GEQUAL = 1
+    ACS_HLINE = 1
+    ACS_LANTERN = 1
+    ACS_LARROW = 1
+    ACS_LEQUAL = 1
+    ACS_LLCORNER = 1
+    ACS_LRCORNER = 1
+    ACS_LTEE = 1
+    ACS_NEQUAL = 1
+    ACS_PI = 1
+    ACS_PLMINUS = 1
+    ACS_PLUS = 1
+    ACS_RARROW = 1
+    ACS_RTEE = 1
+    ACS_S1 = 1
+    ACS_S3 = 1
+    ACS_S7 = 1
+    ACS_S9 = 1
+    ACS_SBBS = 1
+    ACS_SBSB = 1
+    ACS_SBSS = 1
+    ACS_SSBB = 1
+    ACS_SSBS = 1
+    ACS_SSSB = 1
+    ACS_SSSS = 1
+    ACS_STERLING = 1
+    ACS_TTEE = 1
+    ACS_UARROW = 1
+    ACS_ULCORNER = 1
+    ACS_URCORNER = 1
+    ACS_VLINE = 1
+    COLOR_BLACK = 1
+    COLOR_BLUE = 1
+    COLOR_CYAN = 1
+    COLOR_GREEN = 1
+    COLOR_MAGENTA = 1
+    COLOR_RED = 1
+    COLOR_WHITE = 1
+    COLOR_YELLOW = 1
+        ''')
+
+
+astroid.register_module_extender(astroid.MANAGER, 'curses', _curses_transform)
diff --git a/astroid/brain/brain_fstrings.py b/astroid/brain/brain_fstrings.py
index e4c9357..25a5c89 100644
--- a/astroid/brain/brain_fstrings.py
+++ b/astroid/brain/brain_fstrings.py
@@ -27,7 +27,7 @@ def _clone_node_with_lineno(node, parent, lineno):
             for param in other_fields
         })
     new_node = cls(**init_params)
-    if hasattr(node, 'postinit'):
+    if hasattr(node, 'postinit') and _astroid_fields:
         new_node.postinit(**postinit_params)
     return new_node
 
@@ -58,4 +58,3 @@ if sys.version_info[:2] >= (3, 6):
     astroid.MANAGER.register_transform(
         astroid.FormattedValue,
         _transform_formatted_value)
-
diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py
index b99cb76..765c320 100644
--- a/astroid/brain/brain_namedtuple_enum.py
+++ b/astroid/brain/brain_namedtuple_enum.py
@@ -20,47 +20,70 @@ from astroid import nodes
 from astroid.builder import AstroidBuilder, extract_node
 from astroid import util
 
-PY3K = sys.version_info > (3, 0)
-PY33 = sys.version_info >= (3, 3)
-PY34 = sys.version_info >= (3, 4)
 
-# general function
+def _infer_first(node, context):
+    if node is util.Uninferable:
+        raise UseInferenceDefault
+    try:
+        value = next(node.infer(context=context))
+        if value is util.Uninferable:
+            raise UseInferenceDefault()
+        else:
+            return value
+    except StopIteration:
+        raise InferenceError()
+
+
+def _find_func_form_arguments(node, context):
+
+    def _extract_namedtuple_arg_or_keyword(position, key_name=None):
+
+        if len(args) > position:
+            return _infer_first(args[position], context)
+        if key_name and key_name in found_keywords:
+            return _infer_first(found_keywords[key_name], context)
+
+    args = node.args
+    keywords = node.keywords
+    found_keywords = {
+        keyword.arg: keyword.value for keyword in keywords
+    } if keywords else {}
+
+    name = _extract_namedtuple_arg_or_keyword(
+        position=0,
+        key_name='typename'
+    )
+    names = _extract_namedtuple_arg_or_keyword(
+        position=1,
+        key_name='field_names'
+    )
+    if name and names:
+        return name.value, names
+
+    raise UseInferenceDefault()
+
 
 def infer_func_form(node, base_type, context=None, enum=False):
     """Specific inference function for namedtuple or Python 3 enum. """
-    def infer_first(node):
-        if node is util.Uninferable:
-            raise UseInferenceDefault
-        try:            
-            value = next(node.infer(context=context))
-            if value is util.Uninferable:
-                raise UseInferenceDefault()
-            else:
-                return value
-        except StopIteration:
-            raise InferenceError()
-
     # node is a Call node, class name as first argument and generated class
     # attributes as second argument
-    if len(node.args) != 2:
-        # something weird here, go back to class implementation
-        raise UseInferenceDefault()
+
     # namedtuple or enums list of attributes can be a list of strings or a
     # whitespace-separate string
     try:
-        name = infer_first(node.args[0]).value
-        names = infer_first(node.args[1])
+        name, names = _find_func_form_arguments(node, context)
         try:
             attributes = names.value.replace(',', ' ').split()
         except AttributeError:
             if not enum:
-                attributes = [infer_first(const).value for const in names.elts]
+                attributes = [_infer_first(const, context).value
+                              for const in names.elts]
             else:
                 # Enums supports either iterator of (name, value) pairs
                 # or mappings.
                 # TODO: support only list, tuples and mappings.
                 if hasattr(names, 'items') and isinstance(names.items, list):
-                    attributes = [infer_first(const[0]).value
+                    attributes = [_infer_first(const[0], context).value
                                   for const in names.items
                                   if isinstance(const[0], nodes.Const)]
                 elif hasattr(names, 'elts'):
@@ -69,11 +92,11 @@ def infer_func_form(node, base_type, context=None, enum=False):
                     # be mixed.
                     if all(isinstance(const, nodes.Tuple)
                            for const in names.elts):
-                        attributes = [infer_first(const.elts[0]).value
+                        attributes = [_infer_first(const.elts[0], context).value
                                       for const in names.elts
                                       if isinstance(const, nodes.Tuple)]
                     else:
-                        attributes = [infer_first(const).value
+                        attributes = [_infer_first(const, context).value
                                       for const in names.elts]
                 else:
                     raise AttributeError
@@ -125,6 +148,11 @@ def infer_named_tuple(node, context=None):
     if rename:
         attributes = _get_renamed_namedtuple_atributes(attributes)
 
+    replace_args = ', '.join(
+        '{arg}=None'.format(arg=arg)
+        for arg in attributes
+    )
+
     field_def = ("    {name} = property(lambda self: self[{index:d}], "
                  "doc='Alias for field number {index:d}')")
     field_defs = '\n'.join(field_def.format(name=name, index=index)
@@ -138,12 +166,15 @@ class %(name)s(tuple):
     @classmethod
     def _make(cls, iterable, new=tuple.__new__, len=len):
         return new(cls, iterable)
-    def _replace(self, **kwds):
+    def _replace(self, %(replace_args)s):
         return self
     def __getnewargs__(self):
         return tuple(self)
 %(field_defs)s
-    ''' % {'name': name, 'fields': attributes, 'field_defs': field_defs})
+    ''' % {'name': name,
+           'fields': attributes,
+           'field_defs': field_defs,
+           'replace_args': replace_args})
     class_node.locals['_asdict'] = fake.body[0].locals['_asdict']
     class_node.locals['_make'] = fake.body[0].locals['_make']
     class_node.locals['_replace'] = fake.body[0].locals['_replace']
@@ -159,7 +190,7 @@ def _get_renamed_namedtuple_atributes(field_names):
     seen = set()
     for i, name in enumerate(field_names):
         if (not all(c.isalnum() or c == '_' for c in name) or keyword.iskeyword(name)
-            or not name or name[0].isdigit() or name.startswith('_') or name in seen):
+                or not name or name[0].isdigit() or name.startswith('_') or name in seen):
             names[i] = '_%d' % i
         seen.add(name)
     return tuple(names)
@@ -175,6 +206,24 @@ def infer_enum(node, context=None):
                 name = ''
                 value = 0
             return EnumAttribute()
+        def __iter__(self):
+            class EnumAttribute(object):
+                name = ''
+                value = 0
+            return [EnumAttribute()]
+        def __next__(self):
+            return next(iter(self))
+        def __getitem__(self, attr):
+            class Value(object):
+                @property
+                def name(self):
+                    return ''
+                @property
+                def value(self):
+                    return attr
+
+            return Value()
+        __members__ = ['']
     ''')
     class_node = infer_func_form(node, enum_meta,
                                  context=context, enum=True)[0]
@@ -198,10 +247,13 @@ def infer_enum_class(node):
                 continue
 
             stmt = values[0].statement()
-            if isinstance(stmt.targets[0], nodes.Tuple):
-                targets = stmt.targets[0].itered()
-            else:
-                targets = stmt.targets
+            if isinstance(stmt, nodes.Assign):
+                if isinstance(stmt.targets[0], nodes.Tuple):
+                    targets = stmt.targets[0].itered()
+                else:
+                    targets = stmt.targets
+            elif isinstance(stmt, nodes.AnnAssign):
+                targets = [stmt.target]
 
             new_targets = []
             for target in targets:
diff --git a/astroid/brain/brain_numpy.py b/astroid/brain/brain_numpy.py
index 8acfe05..51df17b 100644
--- a/astroid/brain/brain_numpy.py
+++ b/astroid/brain/brain_numpy.py
@@ -9,42 +9,143 @@
 import astroid
 
 
-# TODO(cpopa): drop when understanding augmented assignments
-
-def numpy_core_transform():
+def numpy_random_mtrand_transform():
     return astroid.parse('''
-    from numpy.core import numeric
-    from numpy.core import fromnumeric
... 7153 lines suppressed ...

-- 
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