summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2024-08-28 10:17:12 +0200
committerGitHub <noreply@github.com>2024-08-28 10:17:12 +0200
commitdf57e1ceb3754e44834263b833299357ac05e87c (patch)
treea8570e1629f3ec0233181f2cccaee38c38caa0b7 /lib
parent59b4b785e0baccc8505e9a22cb843202d039a11c (diff)
downloadspack-df57e1ceb3754e44834263b833299357ac05e87c.tar.gz
spack-df57e1ceb3754e44834263b833299357ac05e87c.tar.bz2
spack-df57e1ceb3754e44834263b833299357ac05e87c.tar.xz
spack-df57e1ceb3754e44834263b833299357ac05e87c.zip
Remove llnl.util.lang.has_method, use built-in hasattr instead (#46072)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/llnl/util/lang.py18
1 files changed, 4 insertions, 14 deletions
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py
index 1856620bb7..d0d9400c32 100644
--- a/lib/spack/llnl/util/lang.py
+++ b/lib/spack/llnl/util/lang.py
@@ -6,7 +6,6 @@
import collections.abc
import contextlib
import functools
-import inspect
import itertools
import os
import re
@@ -91,15 +90,6 @@ def attr_setdefault(obj, name, value):
return getattr(obj, name)
-def has_method(cls, name):
- for base in inspect.getmro(cls):
- if base is object:
- continue
- if name in base.__dict__:
- return True
- return False
-
-
def union_dicts(*dicts):
"""Use update() to combine all dicts into one.
@@ -226,8 +216,8 @@ def key_ordering(cls):
value.__name__ = name
setattr(cls, name, value)
- if not has_method(cls, "_cmp_key"):
- raise TypeError("'%s' doesn't define _cmp_key()." % cls.__name__)
+ if not hasattr(cls, "_cmp_key"):
+ raise TypeError(f"'{cls.__name__}' doesn't define _cmp_key().")
setter("__eq__", lambda s, o: (s is o) or (o is not None and s._cmp_key() == o._cmp_key()))
setter("__lt__", lambda s, o: o is not None and s._cmp_key() < o._cmp_key())
@@ -377,8 +367,8 @@ def lazy_lexicographic_ordering(cls, set_hash=True):
TypeError: If the class does not have a ``_cmp_iter`` method
"""
- if not has_method(cls, "_cmp_iter"):
- raise TypeError("'%s' doesn't define _cmp_iter()." % cls.__name__)
+ if not hasattr(cls, "_cmp_iter"):
+ raise TypeError(f"'{cls.__name__}' doesn't define _cmp_iter().")
# comparison operators are implemented in terms of lazy_eq and lazy_lt
def eq(self, other):