Fix attrs.__version__ deprecation warning (#1145)

This commit is contained in:
allegroai 2023-11-07 16:35:04 +02:00
parent ecdeb2d0a2
commit 68aa2a9e9e

View File

@ -2,12 +2,19 @@ import attr
from .version import Version
try:
# noinspection PyUnresolvedReferences
import importlib.metadata
attr_version = importlib.metadata.version("attrs")
except ImportError:
attr_version = attr.__version__
class attrs(object):
def __init__(self, *args, **kwargs):
if any(x in kwargs for x in ("eq", "order")):
raise RuntimeError("Only `cmp` is supported for attr.attrs, not `eq` or `order`")
if Version(attr.__version__) >= Version("19.2"):
if Version(attr_version) >= Version("19.2"):
cmp = kwargs.pop("cmp", None)
if cmp is not None:
kwargs["eq"] = kwargs["order"] = cmp