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 From 45670a987ffd0baf832be7d95d69cae1c27b3745 Mon Sep 17 00:00:00 2001
Author: Bryce Guinta <bryce.paul.guinta@gmail.com> From: Bryce Guinta <bryce.paul.guinta@gmail.com>
Date: Sun Jan 7 14:28:42 2018 -0700 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 ++++++++++++++++++++++++++++++++---- astroid/brain/brain_six.py | 41 ++++++++++++++++++++++++++++-----
1 file changed, 34 insertions(+), 4 deletions(-) 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 diff --git a/astroid/brain/brain_six.py b/astroid/brain/brain_six.py
index 548d9761..1db6566a 100644 index 9596a6c8..2c09d567 100644
--- a/astroid/brain/pysix_moves.py --- a/astroid/brain/brain_six.py
+++ b/astroid/brain/pysix_moves.py +++ b/astroid/brain/brain_six.py
@@ -23,7 +23,8 @@ @@ -23,7 +23,7 @@ from textwrap import dedent
from astroid import MANAGER, register_module_extender from astroid import MANAGER, register_module_extender
from astroid.builder import AstroidBuilder from astroid.builder import AstroidBuilder
-from astroid.exceptions import AstroidBuildingException -from astroid.exceptions import AstroidBuildingException, InferenceError
+from astroid.exceptions import AstroidBuildingException, NotFoundError +from astroid.exceptions import AstroidBuildingError, InferenceError, AttributeInferenceError
+from astroid import nodes 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 @@ -113,7 +113,7 @@ if sys.version_info[0] == 2:
from StringIO import StringIO splitquery = _urllib.splitquery
from cStringIO import StringIO as cStringIO splittag = _urllib.splittag
from UserDict import UserDict splituser = _urllib.splituser
@@ -194,7 +196,7 @@ - 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.entities as html_entities
import html.parser as html_parser import html.parser as html_parser
import http.client as http_client import http.client as http_client
...@@ -41,7 +41,7 @@ index 548d9761..1db6566a 100644 ...@@ -41,7 +41,7 @@ index 548d9761..1db6566a 100644
BaseHTTPServer = CGIHTTPServer = SimpleHTTPServer = http.server BaseHTTPServer = CGIHTTPServer = SimpleHTTPServer = http.server
import pickle as cPickle import pickle as cPickle
import queue import queue
@@ -225,7 +227,8 @@ @@ -230,7 +230,8 @@ else:
import tkinter.filedialog as tkinter_tkfiledialog import tkinter.filedialog as tkinter_tkfiledialog
import tkinter.font as tkinter_font import tkinter.font as tkinter_font
import tkinter.messagebox as tkinter_messagebox import tkinter.messagebox as tkinter_messagebox
...@@ -51,11 +51,12 @@ index 548d9761..1db6566a 100644 ...@@ -51,11 +51,12 @@ index 548d9761..1db6566a 100644
import urllib.robotparser as urllib_robotparser import urllib.robotparser as urllib_robotparser
import urllib.parse as urllib_parse import urllib.parse as urllib_parse
import urllib.error as urllib_error import urllib.error as urllib_error
@@ -248,10 +251,38 @@ @@ -253,10 +254,38 @@ def six_moves_transform():
def _six_fail_hook(modname): def _six_fail_hook(modname):
- if modname != 'six.moves': - if modname != 'six.moves':
- raise AstroidBuildingException
+ """Fix six.moves imports due to the dynamic nature of this + """Fix six.moves imports due to the dynamic nature of this
+ class. + class.
+ +
...@@ -72,7 +73,7 @@ index 548d9761..1db6566a 100644 ...@@ -72,7 +73,7 @@ index 548d9761..1db6566a 100644
+ attribute_of = (modname != "six.moves" and + attribute_of = (modname != "six.moves" and
+ modname.startswith("six.moves")) + modname.startswith("six.moves"))
+ if modname != 'six.moves' and not attribute_of: + if modname != 'six.moves' and not attribute_of:
raise AstroidBuildingException + raise AstroidBuildingError(modname=modname)
module = AstroidBuilder(MANAGER).string_build(_IMPORTS) module = AstroidBuilder(MANAGER).string_build(_IMPORTS)
module.name = 'six.moves' module.name = 'six.moves'
+ if attribute_of: + if attribute_of:
...@@ -81,8 +82,8 @@ index 548d9761..1db6566a 100644 ...@@ -81,8 +82,8 @@ index 548d9761..1db6566a 100644
+ attribute = modname[start_index:].lstrip(".").replace(".", "_") + attribute = modname[start_index:].lstrip(".").replace(".", "_")
+ try: + try:
+ import_attr = module.getattr(attribute)[0] + import_attr = module.getattr(attribute)[0]
+ except NotFoundError: + except AttributeInferenceError:
+ raise AstroidBuildingException + raise AstroidBuildingError(modname=modname)
+ if isinstance(import_attr, nodes.Import): + if isinstance(import_attr, nodes.Import):
+ submodule = MANAGER.ast_from_module_name(import_attr.names[0][0]) + submodule = MANAGER.ast_from_module_name(import_attr.names[0][0])
+ return submodule + return submodule
...@@ -90,4 +91,32 @@ index 548d9761..1db6566a 100644 ...@@ -90,4 +91,32 @@ index 548d9761..1db6566a 100644
+ # This will cause an Uninferable result, which is okay + # This will cause an Uninferable result, which is okay
return module 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