Python decorators for str/repr, equality, immutability, and more.
Project description
Decorate-me
Python decorators for str/repr, equality, immutability, and more.
Save lines and document your class’s behavior at the top.
Just pip install decorateme
and import decorateme
.
Licensed under the Apache License, version 2.0. New issues and pull requests are welcome. Please refer to the contributing guide. Generated with Tyrannosaurus.
List of decorators
String-like methods
- auto_repr_str
- auto_str
- auto_repr
- auto_html (for display in Jupyter)
- auto_info (add a .info method)
Equality
- auto_eq
- auto_hash
- total_ordering (from functools)
Make your class smart
- auto_obj (auto- for eq, str, and repr)
- dataclass (from dataclasses)
Docstring-related
- copy_docstring
- append_docstring
Timing
- takes_seconds
- takes_seconds_named
- auto_timeout
Allow a class to be used as a type
- iterable_over
- collection_over
- sequence_over
- float_type
- int_type
Overriding / inheritance
- final
- overrides
- override_recommended
- ABC (from abc)
- ABCMeta (from abc)
- abstractmethod (from abc)
Mark purpose / use
- internal
- external
- reserved
Multithreading
- thread_safe
- not_thread_safe
Mutability
- mutable
- immutable
Code maturity
- status (code deprecation & immaturity warnings)
Singletons
- auto_singleton
Example of auto_obj
and float_type
:
import decorateme
@decorateme.auto_obj()
@decorateme.float_type('weight')
class Uno:
def __init__(self, weight):
self.weight = weight
print()
light1, light2, heavy = Uno(3.1), Uno(3.1), Uno(12.8)
assert light1 == light2 != heavy
print(light1) # 'Duo(weight=22.3)'
assert light1 * heavy == 39.68
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
decorateme-0.2.1.tar.gz
(13.5 kB
view hashes)
Built Distribution
decorateme-0.2.1-py3-none-any.whl
(11.7 kB
view hashes)
Close
Hashes for decorateme-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfec162a7832fcf595ba4a3d67601067d8bd7b31c0ed66564e64f39b18386608 |
|
MD5 | 6cdfb57833fd7678a0b61e5e2feb4a99 |
|
BLAKE2b-256 | b01e5ec0314a507c70b277c8a21809c4ffaffedddf278ff0ba7d944830921074 |