decorateme._auto
Decorators for adding dunder methods automatically.
Module Contents
Functions
Auto-adds __repr__, __str__, etc., for simple utility classes with no attributes. |
|
|
Auto-adds |
|
Auto-adds a __eq__ function by comparing its attributes. |
|
Auto-adds a __hash__ function by hashing its attributes. |
|
Auto-adds __repr__ and __str__. |
|
Auto-adds |
|
Auto-adds a |
|
Decorator. |
|
Auto-adds a function |
- decorateme._auto.auto_utils()
Auto-adds __repr__, __str__, etc., for simple utility classes with no attributes.
- decorateme._auto.auto_obj()
Auto-adds
__eq__
,__hash__
,__repr__
,__str__
, and_repr_html
. See the decorators for auto_eq, auto_hash, and auto_repr for more details.
- decorateme._auto.auto_eq(only: Optional[AbstractSet[str]] = None, exclude: Optional[Callable[[str], bool]] = None)
Auto-adds a __eq__ function by comparing its attributes.
- Parameters
only – Only include these attributes
exclude – Exclude these attributes
- decorateme._auto.auto_hash(only: Optional[AbstractSet[str]] = None, exclude: Optional[Callable[[str], bool]] = None)
Auto-adds a __hash__ function by hashing its attributes.
- Parameters
only – Only include these attributes
exclude – Exclude these attributes
- decorateme._auto.auto_repr(only: Optional[AbstractSet[str]] = None, exclude: Optional[Callable[[str], bool]] = lambda a: ...)
Auto-adds __repr__ and __str__.
- Parameters
only – Only include these attributes
exclude – Exclude these attributes
- decorateme._auto.auto_str(only: Optional[AbstractSet[str]] = None, exclude: Optional[Callable[[str], bool]] = lambda a: ..., with_address: bool = False)
Auto-adds
__str__
.- Parameters
only – Only include these attributes
exclude – Exclude these attributes
with_address – Include the hex memory address
- decorateme._auto.auto_html(only: Optional[AbstractSet[str]] = None, exclude: Optional[Callable[[str], bool]] = lambda a: ..., with_address: bool = True)
Auto-adds a
_repr_html
method, which Jupyter will use.- Parameters
only – Only include these attributes
exclude – Exclude these attributes
with_address – Include the hex memory address
- decorateme._auto.auto_repr_str(exclude_simple: Optional[Callable[[str], bool]] = lambda a: ..., exclude_html: Optional[Callable[[str], bool]] = lambda a: ..., exclude_all: Optional[Callable[[str], bool]] = lambda a: ...)
Decorator. Auto-adds
__repr__
,__str__
, and_repr_html_
that show the attributes:__str__
will include attributes in neitherexclude_all
norexclude_simple
_repr_html_
will include attributes in neitherexclude_all
norexclude_simple
and will show the hexadecimal address
__repr__
will include attributes not in exclude_all and will show the hexadecimal address
The
_repr_html_
will be used by Jupyter display.Example
repr(point) == Point(angle=0.3, radius=4, _style='point' @ 0x5528ca3) str(point) == Point(angle=0.3, radius=4) _repr_html_(point) == Point(angle=0.3, radius=4 @ 0x5528ca3)
- Parameters
exclude_simple – Exclude attributes matching these names in human-readable strings (str and _repr_html)
exclude_html – Exclude for _repr_html
exclude_all – Exclude these attributes in all the functions
- decorateme._auto.auto_info(only: Optional[AbstractSet[str]] = None, exclude: Optional[Callable[[str], bool]] = lambda a: ...)
Auto-adds a function
info
that outputs a pretty multi-line representation of the instance and its attributes.- Parameters
only – Only include these attributes
exclude – Exclude these attributes