decorateme._auto

Decorators for adding dunder methods automatically.

Module Contents

Functions

auto_utils()

Auto-adds __repr__, __str__, etc., for simple utility classes with no attributes.

auto_obj()

Auto-adds __eq__, __hash__, __repr__, __str__, and _repr_html.

auto_eq([only, exclude])

Auto-adds a __eq__ function by comparing its attributes.

auto_hash([only, exclude])

Auto-adds a __hash__ function by hashing its attributes.

auto_repr([only, exclude])

Auto-adds __repr__ and __str__.

auto_str([only, exclude, with_address])

Auto-adds __str__.

auto_html([only, exclude, with_address])

Auto-adds a _repr_html method, which Jupyter will use.

auto_repr_str([exclude_simple, exclude_html, exclude_all])

Decorator.

auto_info([only, exclude])

Auto-adds a function info that outputs a pretty multi-line representation of the instance and its attributes.

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 neither exclude_all nor exclude_simple

  • _repr_html_ will include attributes in neither exclude_all nor exclude_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