Accepting request 880615 from devel:languages:python

OBS-URL: https://build.opensuse.org/request/show/880615
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/python-astroid?expand=0&rev=27
This commit is contained in:
Richard Brown 2021-04-01 12:15:49 +00:00 committed by Git OBS Bridge
commit d27b7b8f9a
6 changed files with 81 additions and 225 deletions

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2f4078c2a41bf377eea06d71c9d2ba4eb8f6b1af2135bec27bbbb7d8f12bb703
size 310972

3
astroid-2.5.1.tar.gz Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cfc35498ee64017be059ceffab0a25bedf7548ab76f2bea691c5565896e7128d
size 312511

View File

@ -1,198 +0,0 @@
From 389fbcfd675b914f53617a0de04f1184bd915fce Mon Sep 17 00:00:00 2001
From: Derek Gustafson <degustaf@gmail.com>
Date: Wed, 17 Jul 2019 22:19:47 -0400
Subject: [PATCH] Partially remove dependency on imp.
---
astroid/brain/brain_six.py | 2 +-
astroid/interpreter/_import/spec.py | 89 +++++++++++--------
astroid/modutils.py | 27 ++++--
astroid/scoped_nodes.py | 1 +
.../tests/testdata/python2/data/nonregr.py | 4 +-
.../tests/testdata/python3/data/nonregr.py | 4 +-
astroid/tests/unittest_brain.py | 6 +-
astroid/tests/unittest_modutils.py | 17 ++++
8 files changed, 97 insertions(+), 53 deletions(-)
--- a/astroid/interpreter/_import/spec.py
+++ b/astroid/interpreter/_import/spec.py
@@ -12,17 +12,13 @@ import abc
import collections
import distutils
import enum
-import imp
import os
import sys
import zipimport
-try:
- import importlib.machinery
+import importlib.machinery
- _HAS_MACHINERY = True
-except ImportError:
- _HAS_MACHINERY = False
+_HAS_MACHINERY = True
try:
from functools import lru_cache
@@ -37,22 +33,6 @@ ModuleType = enum.Enum(
"PY_CODERESOURCE PY_COMPILED PY_FROZEN PY_RESOURCE "
"PY_SOURCE PY_ZIPMODULE PY_NAMESPACE",
)
-_ImpTypes = {
- imp.C_BUILTIN: ModuleType.C_BUILTIN,
- imp.C_EXTENSION: ModuleType.C_EXTENSION,
- imp.PKG_DIRECTORY: ModuleType.PKG_DIRECTORY,
- imp.PY_COMPILED: ModuleType.PY_COMPILED,
- imp.PY_FROZEN: ModuleType.PY_FROZEN,
- imp.PY_SOURCE: ModuleType.PY_SOURCE,
-}
-if hasattr(imp, "PY_RESOURCE"):
- _ImpTypes[imp.PY_RESOURCE] = ModuleType.PY_RESOURCE
-if hasattr(imp, "PY_CODERESOURCE"):
- _ImpTypes[imp.PY_CODERESOURCE] = ModuleType.PY_CODERESOURCE
-
-
-def _imp_type_to_module_type(imp_type):
- return _ImpTypes[imp_type]
_ModuleSpec = collections.namedtuple(
@@ -118,23 +98,62 @@ class ImpFinder(Finder):
"""A finder based on the imp module."""
def find_module(self, modname, module_parts, processed, submodule_path):
+ if not isinstance(modname, str):
+ raise TypeError("'modname' must be a str, not {}".format(type(modname)))
if submodule_path is not None:
submodule_path = list(submodule_path)
- try:
- stream, mp_filename, mp_desc = imp.find_module(modname, submodule_path)
- except ImportError:
- return None
-
- # Close resources.
- if stream:
- stream.close()
-
- return ModuleSpec(
- name=modname,
- location=mp_filename,
- module_type=_imp_type_to_module_type(mp_desc[2]),
+ else:
+ try:
+ loader = importlib.util.find_spec(modname)
+ if loader:
+ if loader.loader is importlib.machinery.BuiltinImporter:
+ return ModuleSpec(
+ name=modname,
+ location=None,
+ module_type=ModuleType.C_BUILTIN,
+ )
+ if loader.loader is importlib.machinery.FrozenImporter:
+ return ModuleSpec(
+ name=modname,
+ location=None,
+ module_type=ModuleType.PY_FROZEN,
+ )
+ except ValueError:
+ pass
+ submodule_path = sys.path
+
+ suffixes = (
+ [
+ (s, ModuleType.C_EXTENSION)
+ for s in importlib.machinery.EXTENSION_SUFFIXES
+ ]
+ + [(s, ModuleType.PY_SOURCE) for s in importlib.machinery.SOURCE_SUFFIXES]
+ + [
+ (s, ModuleType.PY_COMPILED)
+ for s in importlib.machinery.BYTECODE_SUFFIXES
+ ]
)
+ for entry in submodule_path:
+ package_directory = os.path.join(entry, modname)
+ for suffix in [".py", importlib.machinery.BYTECODE_SUFFIXES[0]]:
+ package_file_name = "__init__" + suffix
+ file_path = os.path.join(package_directory, package_file_name)
+ if os.path.isfile(file_path):
+ return ModuleSpec(
+ name=modname,
+ location=package_directory,
+ module_type=ModuleType.PKG_DIRECTORY,
+ )
+ for suffix, type_ in suffixes:
+ file_name = modname + suffix
+ file_path = os.path.join(entry, file_name)
+ if os.path.isfile(file_path):
+ return ModuleSpec(
+ name=modname, location=file_path, module_type=type_
+ )
+ return None
+
def contribute_to_path(self, spec, processed):
if spec.location is None:
# Builtin.
--- a/astroid/modutils.py
+++ b/astroid/modutils.py
@@ -32,6 +32,7 @@
:var BUILTIN_MODULES: dictionary with builtin module names has key
"""
import imp
+import importlib.util
import os
import platform
import sys
@@ -418,7 +419,9 @@ def file_info_from_modpath(modpath, path
elif modpath == ["os", "path"]:
# FIXME: currently ignoring search_path...
return spec.ModuleSpec(
- name="os.path", location=os.path.__file__, module_type=imp.PY_SOURCE
+ name="os.path",
+ location=os.path.__file__,
+ module_type=spec.ModuleType.PY_SOURCE,
)
return _spec_from_modpath(modpath, path, context)
@@ -614,16 +617,22 @@ def is_relative(modname, from_file):
from_file = os.path.dirname(from_file)
if from_file in sys.path:
return False
- try:
- stream, _, _ = imp.find_module(modname.split(".")[0], [from_file])
+ name = os.path.basename(from_file)
+ file_path = os.path.dirname(from_file)
+ parent_spec = importlib.util.find_spec(name, from_file)
+ while parent_spec is None and len(file_path) > 0:
+ name = os.path.basename(file_path) + "." + name
+ file_path = os.path.dirname(file_path)
+ parent_spec = importlib.util.find_spec(name, from_file)
- # Close the stream to avoid ResourceWarnings.
- if stream:
- stream.close()
- return True
- except ImportError:
+ if parent_spec is None:
return False
+ submodule_spec = importlib.util.find_spec(
+ name + "." + modname.split(".")[0], parent_spec.submodule_search_locations
+ )
+ return submodule_spec is not None
+
# internal only functions #####################################################
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -1405,6 +1405,7 @@ class FunctionDef(mixins.MultiLineBlockM
self.type_comment_returns = type_comment_returns
self.type_comment_args = type_comment_args
+ # pylint: disable=invalid-overridden-method
@decorators_mod.cachedproperty
def extra_decorators(self):
"""The extra decorators that this function can have.

View File

@ -1,3 +1,75 @@
-------------------------------------------------------------------
Sun Mar 21 23:20:02 UTC 2021 - Ben Greiner <code@bnavigator.de>
- Update to 2.5.1
* The context.path is reverted to a set because otherwise it
leads to false positives for non `numpy` functions.
* Don't transform dataclass ClassVars
* Improve typing.TypedDict inference
* Fix the `Duplicates found in MROs` false positive.
- Release 2.5.0
* Adds `attr_fset` in the `PropertyModel` class.
* Remove support for Python 3.5.
* Remove the runtime dependency on six. The six brain
remains in astroid.
* Enrich the brain_collection module so that __class_getitem__
method is added to `deque` for
python version above 3.9.
* The context.path is now a dict and the context.push method
returns True if the node has been visited a certain amount of
times.
* Adds a brain for type object so that it is possible to write
`type[int]` in annotation.
* Add __class_getitem__ method to subprocess.Popen brain under
Python 3.9 so that it is seen as subscriptable by pylint.
* Adds `degrees`, `radians`, which are `numpy ufunc` functions,
in the `numpy` brain. Adds `random` function in the `numpy.
random` brain.
* Fix deprecated importlib methods
* Fix a crash in inference caused by `Uninferable` container
elements
* Add `python 3.9` support.
* The flat attribute of numpy.ndarray is now inferred as an
numpy.ndarray itself. It should be a numpy.flatiter instance,
but this class is not yet available in the numpy brain.
* Fix a bug for dunder methods inference of function objects
* Fixes a bug in the signature of the ndarray.__or__ method,
in the brain_numpy_ndarray.py module.
* Fixes a to-list cast bug in starred_assigned_stmts method,
in the protocols.py` module.
* Added a brain for hypothesis.strategies.composite
* The transpose of a numpy.ndarray is also a numpy.ndarray
* Added a brain for sqlalchemy.orm.session
* Separate string and bytes classes patching
* Prevent recursion error for self referential length calls
* Added missing methods to the brain for mechanize, to fix
pylint false positives
* Added more supported parameters to subprocess.check_output
* Fix recursion errors with pandas
* Added exception inference for `UnicodeDecodeError`
* `FunctionDef.is_generator` properly handles `yield` nodes in
`If` tests
* Fixed exception-chaining error messages.
* Fix failure to infer base class type with multiple inheritance
and qualified names
* Fix interpretation of six.with_metaclass class definitions.
* Reduce memory usage of astroid's module cache.
* Remove dependency on `imp`.
* Do not crash when encountering starred assignments in enums.
* Fix a crash in functools.partial inference when the arguments
cannot be determined
* Fix a crash caused by a lookup of a monkey-patched method
* is_generator correctly considers `Yield` nodes in `AugAssign`
nodes
This fixes a false positive with the
`assignment-from-no-return` pylint check.
* Corrected the parent of function type comment nodes.
These nodes used to be parented to their original ast.
FunctionDef parent but are now correctly parented to their
astroid.FunctionDef parent.
- Drop part_rm_dep_imp.patch fixed upstream
- Drop unpin-deps.patch unpinned upstream
-------------------------------------------------------------------
Sat Dec 5 22:49:26 UTC 2020 - Benjamin Greiner <code@bnavigator.de>

View File

@ -1,7 +1,7 @@
#
# spec file for package python-astroid
#
# Copyright (c) 2020 SUSE LLC
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@ -19,30 +19,25 @@
%define skip_python2 1
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name: python-astroid
Version: 2.4.2
Version: 2.5.1
Release: 0
Summary: Representation of Python source as an AST for pylint
License: LGPL-2.1-or-later
URL: https://github.com/pycqa/astroid
Source: https://files.pythonhosted.org/packages/source/a/astroid/astroid-%{version}.tar.gz
Patch0: unpin-deps.patch
# PATCH-FIX-UPSTREAM part_rm_dep_imp.patch gh#PyCQA/astroid#686 mcepl@suse.com
Patch1: part_rm_dep_imp.patch
BuildRequires: %{python_module lazy-object-proxy >= 1.4}
BuildRequires: %{python_module pytest-runner}
BuildRequires: %{python_module pytest}
BuildRequires: %{python_module setuptools}
BuildRequires: %{python_module six >= 1.12}
BuildRequires: %{python_module typed-ast >= 1.4 if %python-base < 3.8}
BuildRequires: %{python_module wrapt >= 1.11}
BuildRequires: fdupes
BuildRequires: python-rpm-macros
Requires: python-lazy-object-proxy >= 1.4
Requires: python-six >= 1.12
Requires: python-wrapt >= 1.11
BuildArch: noarch
%if 0%{?suse_version} <= 1500
BuildRequires: %{python_module typed-ast}
Requires: python-typed-ast
%if 0%{?python_version_nodots} < 38
Requires: python-typed-ast >= 1.4
%endif
%python_subpackages
@ -77,6 +72,6 @@ objects.
%license COPYING COPYING.LESSER
%doc ChangeLog README.rst
%{python_sitelib}/astroid/
%{python_sitelib}/astroid-*.egg-info
%{python_sitelib}/astroid-%{version}*-info
%changelog

View File

@ -1,13 +0,0 @@
Index: astroid-2.4.1/astroid/__pkginfo__.py
===================================================================
--- astroid-2.4.1.orig/astroid/__pkginfo__.py
+++ astroid-2.4.1/astroid/__pkginfo__.py
@@ -26,7 +26,7 @@ numversion = tuple(int(elem) for elem in
extras_require = {}
install_requires = [
- "lazy_object_proxy==1.4.*",
+ "lazy_object_proxy>=1.4",
"six~=1.12",
"wrapt~=1.11",
'typed-ast>=1.4.0,<1.5;implementation_name== "cpython" and python_version<"3.8"',