decorateme

Metadata for decorateme.

Submodules

Package Contents

Classes

CodeStatus

An enum for the quality/maturity of code,

Functions

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_html([only, exclude, with_address])

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

auto_info([only, exclude])

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

auto_obj()

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

auto_repr([only, exclude])

Auto-adds __repr__ and __str__.

auto_repr_str([exclude_simple, exclude_html, exclude_all])

Decorator.

auto_str([only, exclude, with_address])

Auto-adds __str__.

auto_utils()

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

auto_singleton(cls)

Makes it so the constructor returns a singleton instance.

immutable(mutableclass)

Decorator for making a slot-based class immutable.

mutable(cls)

Just marks an object as mutable.

takes_seconds(x, *args, **kwargs)

Prints a statement like "Done. Took 15.2s." after the function returns.

takes_seconds_named(x, *args, **kwargs)

Prints a statement like "Call to calc_distances took 15.2s." after the function returns.

append_docstring(→ None)

Appends the docstring from from_obj to the docstring for this function or class.

copy_docstring(→ None)

Copies the docstring from from_obj to this function or class.

external(→ T)

This class or package is meant to be used only by code outside this project.

internal(→ T)

This class or package is meant to be used only by code within this project.

not_thread_safe(→ T)

Just marks that something is not thread-safe.

override_recommended(→ T)

Overriding this class is suggested.

overrides(→ T)

Overriding this class is generally recommended (but not required).

reserved(→ T)

This package, class, or function is empty but is declared for future use.

thread_safe(→ T)

Just marks that something is thread-safe.

collection_over(attribute)

Auto-adds an __iter__ and __len__ over elements in a collection attribute.

float_type(attribute)

Auto-adds a __float__ using the __float__ of some attribute.

int_type(attribute)

Auto-adds an __int__ using the __int__ of some attribute.

iterable_over(attribute)

Auto-adds an __iter__ over elements in an iterable attribute.

sequence_over(attribute)

Auto-adds __getitem__ and __len__ over elements in an iterable attribute.

status(level[, vr, msg])

Annotate code quality. Emits a warning if bad code is called.

Attributes

pkg

logger

metadata

metadata

decorateme.pkg
decorateme.logger
decorateme.metadata
decorateme.metadata
decorateme.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_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_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_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

decorateme.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_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_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_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_utils()

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

decorateme.auto_singleton(cls)

Makes it so the constructor returns a singleton instance. The constructor CANNOT take arguments.

Example

@auto_singleton
class MyClass: pass
mysingleton = MyClass()
decorateme.immutable(mutableclass)

Decorator for making a slot-based class immutable. Taken almost verbatim from https://code.activestate.com/recipes/578233-immutable-class-decorator/ Written by Oren Tirosh and released under the MIT license.

decorateme.mutable(cls)

Just marks an object as mutable.

decorateme.takes_seconds(x, *args, **kwargs)

Prints a statement like “Done. Took 15.2s.” after the function returns.

decorateme.takes_seconds_named(x, *args, **kwargs)

Prints a statement like “Call to calc_distances took 15.2s.” after the function returns.

decorateme.append_docstring(from_obj: Type) None

Appends the docstring from from_obj to the docstring for this function or class.

decorateme.copy_docstring(from_obj: Type) None

Copies the docstring from from_obj to this function or class.

decorateme.external(cls: T) T

This class or package is meant to be used only by code outside this project.

decorateme.internal(cls: T) T

This class or package is meant to be used only by code within this project.

decorateme.not_thread_safe(cls: T) T

Just marks that something is not thread-safe.

Overriding this class is suggested.

decorateme.overrides(cls: T) T

Overriding this class is generally recommended (but not required).

decorateme.reserved(cls: T) T

This package, class, or function is empty but is declared for future use.

decorateme.thread_safe(cls: T) T

Just marks that something is thread-safe.

decorateme.collection_over(attribute: str)

Auto-adds an __iter__ and __len__ over elements in a collection attribute. Used to annotate a class as being “essentially a collection” over some elements.

Parameters

attribute – The name of the attribute of this class

decorateme.float_type(attribute: str)

Auto-adds a __float__ using the __float__ of some attribute. Used to annotate a class as being “essentially an float”.

Parameters

attribute – The name of the attribute of this class

decorateme.int_type(attribute: str)

Auto-adds an __int__ using the __int__ of some attribute. Used to annotate a class as being “essentially an integer”.

Parameters

attribute – The name of the attribute of this class

decorateme.iterable_over(attribute: str)

Auto-adds an __iter__ over elements in an iterable attribute. Used to annotate a class as being “essentially an iterable” over some elements.

Parameters

attribute – The name of the attribute of this class

decorateme.sequence_over(attribute: str)

Auto-adds __getitem__ and __len__ over elements in an iterable attribute. Used to annotate a class as being “essentially a list” over some elements.

Parameters

attribute – The name of the attribute of this class

exception decorateme.CodeIncompleteError

Bases: NotImplementedError

The code is not finished.

exception decorateme.CodeRemovedError

Bases: NotImplementedError

The code was removed.

class decorateme.CodeStatus

Bases: enum.Enum

An enum for the quality/maturity of code, ranging from incomplete to deprecated.

INCOMPLETE
PREVIEW
STABLE = 0
PENDING_DEPRECATION = 1
DEPRECATED = 2
REMOVED = 3
classmethod of(x: Union[int, str, CodeStatus]) CodeStatus
exception decorateme.PreviewWarning

Bases: UserWarning

The code being called is a preview, unstable. or immature.

decorateme.status(level: Union[int, str, CodeStatus], vr: Optional[str] = '', msg: Optional[str] = None)

Annotate code quality. Emits a warning if bad code is called.

Parameters
  • level – The quality / maturity

  • vr – First version the status / warning applies to

  • msg – Explanation and/or when it will be removed or completed