decorateme
Metadata for decorateme.
Submodules
Package Contents
Classes
An enum for the quality/maturity of code, |
Functions
|
Auto-adds a __eq__ function by comparing its attributes. |
|
Auto-adds a __hash__ function by hashing its attributes. |
|
Auto-adds a |
|
Auto-adds a function |
|
Auto-adds |
|
Auto-adds __repr__ and __str__. |
|
Decorator. |
|
Auto-adds |
Auto-adds __repr__, __str__, etc., for simple utility classes with no attributes. |
|
|
Makes it so the constructor returns a singleton instance. |
|
Decorator for making a slot-based class immutable. |
|
Just marks an object as mutable. |
|
Prints a statement like "Done. Took 15.2s." after the function returns. |
|
Prints a statement like "Call to calc_distances took 15.2s." after the function returns. |
|
Appends the docstring from from_obj to the docstring for this function or class. |
|
Copies the docstring from from_obj to this function or class. |
|
This class or package is meant to be used only by code outside this project. |
|
This class or package is meant to be used only by code within this project. |
|
Just marks that something is not thread-safe. |
|
Overriding this class is suggested. |
|
Overriding this class is generally recommended (but not required). |
|
This package, class, or function is empty but is declared for future use. |
|
Just marks that something is thread-safe. |
|
Auto-adds an |
|
Auto-adds a |
|
Auto-adds an |
|
Auto-adds an |
|
Auto-adds |
|
Annotate code quality. Emits a warning if bad code is called. |
Attributes
- 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 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_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.
- decorateme.override_recommended(cls: T) T
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