summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarkmcclain <markmcclain@users.noreply.github.com>2019-03-29 04:13:06 -0400
committerClaudiu Popa <pcmanticore@gmail.com>2019-03-29 09:13:06 +0100
commit70ed2cfd68e71a98697b1c13c337499732a801dc (patch)
treedd289537f24de144d7d2b4591ff5dc2576774bc7
parent79d5a3a783cf0b5a729e4e467508e955a0cca55f (diff)
downloadastroid-git-70ed2cfd68e71a98697b1c13c337499732a801dc.tar.gz
make is_standard_module() properly classify extensions (#659)
Extensions can be installed in either a platform independent or specific location[1]. The search is updated to include both paths. Previously, an extension in the platform specific location would be misclassified because only the independent location was considered and the platform specific location shared a prefix with the standard lib. [1] http://docs.python.org/3/distutils/apiref.html#distutils.sysconfig.get_python_lib Fixes Issue: #658 Co-authored-by: Matt Story <s.matt.story@gmail.com>
-rw-r--r--astroid/modutils.py7
-rw-r--r--astroid/tests/unittest_modutils.py2
2 files changed, 5 insertions, 4 deletions
diff --git a/astroid/modutils.py b/astroid/modutils.py
index df75a901..cc5fc56f 100644
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -116,7 +116,7 @@ if os.name == "posix":
# https://github.com/PyCQA/pylint/issues/712#issuecomment-163178753
STD_LIB_DIRS.add(_posix_path("lib64"))
-EXT_LIB_DIR = get_python_lib()
+EXT_LIB_DIRS = {get_python_lib(), get_python_lib(True)}
IS_JYTHON = platform.python_implementation() == "Jython"
BUILTIN_MODULES = dict.fromkeys(sys.builtin_module_names, True)
@@ -596,8 +596,9 @@ def is_standard_module(modname, std_path=None):
# we assume there are no namespaces in stdlib
return not util.is_namespace(modname)
filename = _normalize_path(filename)
- if filename.startswith(_cache_normalize_path(EXT_LIB_DIR)):
- return False
+ for path in EXT_LIB_DIRS:
+ if filename.startswith(_cache_normalize_path(path)):
+ return False
if std_path is None:
std_path = STD_LIB_DIRS
for path in std_path:
diff --git a/astroid/tests/unittest_modutils.py b/astroid/tests/unittest_modutils.py
index 6f1bae14..b517422e 100644
--- a/astroid/tests/unittest_modutils.py
+++ b/astroid/tests/unittest_modutils.py
@@ -278,7 +278,7 @@ class StandardLibModuleTest(resources.SysPathSetup, unittest.TestCase):
def test_custom_path(self):
datadir = resources.find("")
- if datadir.startswith(modutils.EXT_LIB_DIR):
+ if any(datadir.startswith(p) for p in modutils.EXT_LIB_DIRS):
self.skipTest("known breakage of is_standard_module on installed package")
self.assertTrue(modutils.is_standard_module("data.module", (datadir,)))