Commit ec7493e4 authored by Jérome Perrin's avatar Jérome Perrin

wip astroid

parent eb7791ee
From c13857606dda6be0d48a3f40d7466391b5ab951b Mon Sep 17 00:00:00 2001
From: Claudiu Popa <pcmanticore@gmail.com>
Date: Wed, 26 Aug 2015 20:51:18 +0300
Subject: [PATCH] functools.wraps needs to be called with the decorated
function and the implementation of cached decorator was passing the bad
arguments (grafted from 2a66d7f8cf83616b3eac63bcae61efe655678ab7)
--HG--
branch : 1.4.0
---
astroid/bases.py | 1 +
astroid/decorators.py | 7 +++----
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/astroid/bases.py b/astroid/bases.py
index 90d1e4d6..edf6c4ac 100644
--- a/astroid/bases.py
+++ b/astroid/bases.py
@@ -289,6 +289,7 @@ class Generator(Instance):
def path_wrapper(func):
"""return the given infer function wrapped to handle the path"""
+ @functools.wraps(func)
def wrapped(node, context=None, _func=func, **kwargs):
"""wrapper function handling context"""
if context is None:
diff --git a/astroid/decorators.py b/astroid/decorators.py
index 2c6e40b7..a446536c 100644
--- a/astroid/decorators.py
+++ b/astroid/decorators.py
@@ -27,14 +27,13 @@ import wrapt
@wrapt.decorator
def cached(func, instance, args, kwargs):
"""Simple decorator to cache result of method calls without args."""
- wrapped_self, = args
- cache = getattr(wrapped_self, '__cache', None)
+ cache = getattr(instance, '__cache', None)
if cache is None:
- wrapped_self.__cache = cache = {}
+ instance.__cache = cache = {}
try:
return cache[func]
except KeyError:
- cache[func] = result = func(wrapped_self)
+ cache[func] = result = func(*args, **kwargs)
return result
--
2.35.1
commit cf5648658c87b6e3b2fa4394b5921792827246dc
Author: Bryce Guinta <bryce.paul.guinta@gmail.com>
Date: Sun Jan 7 14:28:42 2018 -0700
From 45670a987ffd0baf832be7d95d69cae1c27b3745 Mon Sep 17 00:00:00 2001
From: Bryce Guinta <bryce.paul.guinta@gmail.com>
Date: Sun, 7 Jan 2018 14:28:42 -0700
Subject: [PATCH] Fix submodule import in six.moves
Fix submodule import in six.moves
This commit fixes import errors when modname
started with, but was not equal, to six.moves
This commit fixes import errors when modname
started with, but was not equal, to six.moves
---
astroid/brain/pysix_moves.py | 38 ++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
astroid/brain/brain_six.py | 41 ++++++++++++++++++++++++++++-----
astroid/tests/unittest_brain.py | 14 +++++++++++
2 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/astroid/brain/pysix_moves.py b/astroid/brain/pysix_moves.py
index 548d9761..1db6566a 100644
--- a/astroid/brain/pysix_moves.py
+++ b/astroid/brain/pysix_moves.py
@@ -23,7 +23,8 @@
diff --git a/astroid/brain/brain_six.py b/astroid/brain/brain_six.py
index 9596a6c8..2c09d567 100644
--- a/astroid/brain/brain_six.py
+++ b/astroid/brain/brain_six.py
@@ -23,7 +23,7 @@ from textwrap import dedent
from astroid import MANAGER, register_module_extender
from astroid.builder import AstroidBuilder
-from astroid.exceptions import AstroidBuildingException
+from astroid.exceptions import AstroidBuildingException, NotFoundError
+from astroid import nodes
-from astroid.exceptions import AstroidBuildingException, InferenceError
+from astroid.exceptions import AstroidBuildingError, InferenceError, AttributeInferenceError
from astroid import nodes
def _indent(text, prefix, predicate=None):
"""Adds 'prefix' to the beginning of selected lines in 'text'.
@@ -48,6 +49,7 @@
import CGIHTTPServer
import SimpleHTTPServer
+ import cPickle
from StringIO import StringIO
from cStringIO import StringIO as cStringIO
from UserDict import UserDict
@@ -194,7 +196,7 @@
@@ -113,7 +113,7 @@ if sys.version_info[0] == 2:
splitquery = _urllib.splitquery
splittag = _urllib.splittag
splituser = _urllib.splituser
- uses_fragment = _urlparse.uses_fragment
+ uses_fragment = _urlparse.uses_fragment
uses_netloc = _urlparse.uses_netloc
uses_params = _urlparse.uses_params
uses_query = _urlparse.uses_query
@@ -199,7 +199,7 @@ else:
import html.entities as html_entities
import html.parser as html_parser
import http.client as http_client
......@@ -41,7 +41,7 @@ index 548d9761..1db6566a 100644
BaseHTTPServer = CGIHTTPServer = SimpleHTTPServer = http.server
import pickle as cPickle
import queue
@@ -225,7 +227,8 @@
@@ -230,7 +230,8 @@ else:
import tkinter.filedialog as tkinter_tkfiledialog
import tkinter.font as tkinter_font
import tkinter.messagebox as tkinter_messagebox
......@@ -51,11 +51,12 @@ index 548d9761..1db6566a 100644
import urllib.robotparser as urllib_robotparser
import urllib.parse as urllib_parse
import urllib.error as urllib_error
@@ -248,10 +251,38 @@
@@ -253,10 +254,38 @@ def six_moves_transform():
def _six_fail_hook(modname):
- if modname != 'six.moves':
- raise AstroidBuildingException
+ """Fix six.moves imports due to the dynamic nature of this
+ class.
+
......@@ -72,7 +73,7 @@ index 548d9761..1db6566a 100644
+ attribute_of = (modname != "six.moves" and
+ modname.startswith("six.moves"))
+ if modname != 'six.moves' and not attribute_of:
raise AstroidBuildingException
+ raise AstroidBuildingError(modname=modname)
module = AstroidBuilder(MANAGER).string_build(_IMPORTS)
module.name = 'six.moves'
+ if attribute_of:
......@@ -81,8 +82,8 @@ index 548d9761..1db6566a 100644
+ attribute = modname[start_index:].lstrip(".").replace(".", "_")
+ try:
+ import_attr = module.getattr(attribute)[0]
+ except NotFoundError:
+ raise AstroidBuildingException
+ except AttributeInferenceError:
+ raise AstroidBuildingError(modname=modname)
+ if isinstance(import_attr, nodes.Import):
+ submodule = MANAGER.ast_from_module_name(import_attr.names[0][0])
+ return submodule
......@@ -90,4 +91,32 @@ index 548d9761..1db6566a 100644
+ # This will cause an Uninferable result, which is okay
return module
def transform_six_add_metaclass(node):
diff --git a/astroid/tests/unittest_brain.py b/astroid/tests/unittest_brain.py
index 81ad884c..1d079953 100644
--- a/astroid/tests/unittest_brain.py
+++ b/astroid/tests/unittest_brain.py
@@ -280,6 +280,20 @@ class SixBrainTest(unittest.TestCase):
qname = 'httplib.HTTPSConnection'
self.assertEqual(inferred.qname(), qname)
+ @unittest.skipIf(six.PY2,
+ "The python 2 six brain uses dummy classes")
+ def test_from_submodule_imports(self):
+ """Make sure ulrlib submodules can be imported from
+
+ See PyCQA/pylint#1640 for relevant issue
+ """
+ ast_node = builder.extract_node('''
+ from six.moves.urllib.parse import urlparse
+ urlparse #@
+ ''')
+ inferred = next(ast_node.infer())
+ self.assertIsInstance(inferred, nodes.FunctionDef)
+
@unittest.skipUnless(HAS_MULTIPROCESSING,
'multiprocesing is required for this test, but '
--
2.35.1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment