Simplify attributes decorator
This commit is contained in:
parent
5753281838
commit
564fade925
|
@ -122,13 +122,6 @@ def attributes(maybe_cl=None, add_repr=True, add_cmp=True, add_hash=True,
|
|||
C(_private=42)
|
||||
:type add_init: bool
|
||||
"""
|
||||
# attrs_or class type depends on the usage of the decorator. It's a class
|
||||
# if it's used as `@attributes` but ``None`` (or a value passed) if used
|
||||
# as `@attributes()`.
|
||||
if isinstance(maybe_cl, type):
|
||||
_transform_attrs(maybe_cl)
|
||||
return _add_init(_add_hash(_add_cmp(_add_repr(maybe_cl))))
|
||||
else:
|
||||
def wrap(cl):
|
||||
_transform_attrs(cl)
|
||||
if add_repr is True:
|
||||
|
@ -140,7 +133,12 @@ def attributes(maybe_cl=None, add_repr=True, add_cmp=True, add_hash=True,
|
|||
if add_init is True:
|
||||
cl = _add_init(cl)
|
||||
return cl
|
||||
|
||||
# attrs_or class type depends on the usage of the decorator. It's a class
|
||||
# if it's used as `@attributes` but ``None`` (or a value passed) if used
|
||||
# as `@attributes()`.
|
||||
if isinstance(maybe_cl, type):
|
||||
return wrap(maybe_cl)
|
||||
else:
|
||||
return wrap
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue