Drop now redundant use of inspect (#46057)
inspect.isclass -> isinstance(..., type) inspect.getmro -> cls.__mro__
This commit is contained in:
parent
202e64872a
commit
fb4811ec3f
@ -39,7 +39,6 @@ def _search_duplicate_compilers(error_cls):
|
||||
import collections
|
||||
import collections.abc
|
||||
import glob
|
||||
import inspect
|
||||
import io
|
||||
import itertools
|
||||
import os
|
||||
@ -525,7 +524,7 @@ def _search_for_reserved_attributes_names_in_packages(pkgs, error_cls):
|
||||
name_definitions = collections.defaultdict(list)
|
||||
pkg_cls = spack.repo.PATH.get_pkg_class(pkg_name)
|
||||
|
||||
for cls_item in inspect.getmro(pkg_cls):
|
||||
for cls_item in pkg_cls.__mro__:
|
||||
for name in RESERVED_NAMES:
|
||||
current_value = cls_item.__dict__.get(name)
|
||||
if current_value is None:
|
||||
|
@ -1559,7 +1559,7 @@ def __init__(self, package):
|
||||
|
||||
#: Modules for the classes in the MRO up to PackageBase
|
||||
modules_in_mro = []
|
||||
for cls in inspect.getmro(type(package)):
|
||||
for cls in type(package).__mro__:
|
||||
module = cls.module
|
||||
|
||||
if module == self.current_module:
|
||||
|
@ -25,7 +25,6 @@
|
||||
so package authors should use their judgement.
|
||||
"""
|
||||
import functools
|
||||
import inspect
|
||||
from contextlib import contextmanager
|
||||
|
||||
import spack.directives_meta
|
||||
@ -133,7 +132,7 @@ def __call__(self, package_or_builder_self, *args, **kwargs):
|
||||
# its superclasses for successive calls. We don't have that
|
||||
# information within `SpecMultiMethod`, because it is not
|
||||
# associated with the package class.
|
||||
for cls in inspect.getmro(package_or_builder_self.__class__)[1:]:
|
||||
for cls in package_or_builder_self.__class__.__mro__[1:]:
|
||||
superself = cls.__dict__.get(self.__name__, None)
|
||||
|
||||
if isinstance(superself, SpecMultiMethod):
|
||||
|
@ -878,7 +878,7 @@ def fullname(cls):
|
||||
def fullnames(cls):
|
||||
"""Fullnames for this package and any packages from which it inherits."""
|
||||
fullnames = []
|
||||
for cls in inspect.getmro(cls):
|
||||
for cls in cls.__mro__:
|
||||
namespace = getattr(cls, "namespace", None)
|
||||
if namespace:
|
||||
fullnames.append("%s.%s" % (namespace, cls.name))
|
||||
|
@ -4,7 +4,6 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
|
||||
import hashlib
|
||||
import inspect
|
||||
import os
|
||||
import os.path
|
||||
import pathlib
|
||||
@ -185,8 +184,8 @@ def __init__(
|
||||
# search mro to look for the file
|
||||
abs_path: Optional[str] = None
|
||||
# At different times we call FilePatch on instances and classes
|
||||
pkg_cls = pkg if inspect.isclass(pkg) else pkg.__class__
|
||||
for cls in inspect.getmro(pkg_cls): # type: ignore
|
||||
pkg_cls = pkg if isinstance(pkg, type) else pkg.__class__
|
||||
for cls in pkg_cls.__mro__: # type: ignore
|
||||
if not hasattr(cls, "module"):
|
||||
# We've gone too far up the MRO
|
||||
break
|
||||
|
@ -1281,7 +1281,7 @@ def get_pkg_class(self, pkg_name: str) -> Type["spack.package_base.PackageBase"]
|
||||
raise RepoError(msg) from e
|
||||
|
||||
cls = getattr(module, class_name)
|
||||
if not inspect.isclass(cls):
|
||||
if not isinstance(cls, type):
|
||||
tty.die(f"{pkg_name}.{class_name} is not a class")
|
||||
|
||||
# Clear any prior changes to class attributes in case the class was loaded from the
|
||||
|
@ -2,7 +2,6 @@
|
||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
import inspect
|
||||
import os
|
||||
import platform
|
||||
import posixpath
|
||||
@ -593,7 +592,7 @@ def test_setting_attributes(self, default_mock_concretization):
|
||||
|
||||
# We can also propagate the settings to classes in the MRO
|
||||
module_wrapper.propagate_changes_to_mro()
|
||||
for cls in inspect.getmro(type(s.package)):
|
||||
for cls in type(s.package).__mro__:
|
||||
current_module = cls.module
|
||||
if current_module == spack.package_base:
|
||||
break
|
||||
|
@ -2,7 +2,6 @@
|
||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
import inspect
|
||||
import itertools
|
||||
import os
|
||||
import re
|
||||
@ -700,7 +699,7 @@ def test_parse_multiple_specs(text, tokens, expected_specs):
|
||||
],
|
||||
)
|
||||
def test_cli_spec_roundtrip(args, expected):
|
||||
if inspect.isclass(expected) and issubclass(expected, BaseException):
|
||||
if isinstance(expected, type) and issubclass(expected, BaseException):
|
||||
with pytest.raises(expected):
|
||||
spack.cmd.parse_specs(args)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user