Remove llnl.util.lang.has_method, use built-in hasattr instead (#46072)
This commit is contained in:
parent
59b4b785e0
commit
df57e1ceb3
@ -6,7 +6,6 @@
|
|||||||
import collections.abc
|
import collections.abc
|
||||||
import contextlib
|
import contextlib
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -91,15 +90,6 @@ def attr_setdefault(obj, name, value):
|
|||||||
return getattr(obj, name)
|
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):
|
def union_dicts(*dicts):
|
||||||
"""Use update() to combine all dicts into one.
|
"""Use update() to combine all dicts into one.
|
||||||
|
|
||||||
@ -226,8 +216,8 @@ def setter(name, value):
|
|||||||
value.__name__ = name
|
value.__name__ = name
|
||||||
setattr(cls, name, value)
|
setattr(cls, name, value)
|
||||||
|
|
||||||
if not has_method(cls, "_cmp_key"):
|
if not hasattr(cls, "_cmp_key"):
|
||||||
raise TypeError("'%s' doesn't define _cmp_key()." % cls.__name__)
|
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("__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())
|
setter("__lt__", lambda s, o: o is not None and s._cmp_key() < o._cmp_key())
|
||||||
@ -377,8 +367,8 @@ def cd_fun():
|
|||||||
TypeError: If the class does not have a ``_cmp_iter`` method
|
TypeError: If the class does not have a ``_cmp_iter`` method
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if not has_method(cls, "_cmp_iter"):
|
if not hasattr(cls, "_cmp_iter"):
|
||||||
raise TypeError("'%s' doesn't define _cmp_iter()." % cls.__name__)
|
raise TypeError(f"'{cls.__name__}' doesn't define _cmp_iter().")
|
||||||
|
|
||||||
# comparison operators are implemented in terms of lazy_eq and lazy_lt
|
# comparison operators are implemented in terms of lazy_eq and lazy_lt
|
||||||
def eq(self, other):
|
def eq(self, other):
|
||||||
|
Loading…
Reference in New Issue
Block a user