Simple annotations to automatically generate __str__(self), __repr__(self) and __eq__(self, other) methods in classes
Project description
simplestr
A python package with annotations to automatically generate __str__(self)
, __repr__(self)
and __eq__(self, other)
methods in classes
Description
This package provides only two annotations:
@gen_str
to generate__str__(self)
method@gen_repr
to generate__repr__(self)
method@gen_eq
to generate__eq__(self, other)
method@gen_str_repr
to generate both__str__(self)
and__repr__(self)
methods@gen_str_repr_eq
to generate both__str__(self)
,__repr__(self)
and__eq__(self, other)
methods
Installation
Normal installation
pip install simplestr
Development installation
git clone https://github.com/jpleorx/simplestr.git
cd simplestr
pip install --editable .
Example A (with separate annotations)
from simplestr import gen_str, gen_repr, gen_eq
@gen_str
@gen_repr
@gen_eq
class Rect:
def __init__(self, x: int, y: int, w: int, h: int):
self.x = x
self.y = y
self.w = w
self.h = h
rect1 = Rect(1, 2, 3, 4)
rect2 = Rect(10, 20, 30, 40)
print(rect1)
print(rect2)
print([rect1, rect2])
print(rect1 == rect2)
print(rect1 == Rect(1, 2, 3, 4))
Rect{x=1, y=2, w=3, h=4}
Rect{x=10, y=20, w=30, h=40}
[Rect{x=1, y=2, w=3, h=4}, Rect{x=10, y=20, w=30, h=40}]
False
True
Example B (with joined annotation)
from simplestr import gen_str_repr_eq
@gen_str_repr_eq
class Rect:
def __init__(self, x: int, y: int, w: int, h: int):
self.x = x
self.y = y
self.w = w
self.h = h
rect1 = Rect(1, 2, 3, 4)
rect2 = Rect(10, 20, 30, 40)
print(rect1)
print(rect2)
print([rect1, rect2])
print(rect1 == rect2)
print(rect1 == Rect(1, 2, 3, 4))
Rect{x=1, y=2, w=3, h=4}
Rect{x=10, y=20, w=30, h=40}
[Rect{x=1, y=2, w=3, h=4}, Rect{x=10, y=20, w=30, h=40}]
False
True
Links
In case you’d like to check my other work or contact me:
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
simplestr-0.4.1.tar.gz
(9.2 kB
view hashes)
Built Distribution
Close
Hashes for simplestr-0.4.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0134207cff52fc58bae16a3724dfffead33fb2505165d87318291c72860c5262 |
|
MD5 | 7bafe16d039d619fda8fef55796e43df |
|
BLAKE2b-256 | ae5e9d9d2594ae5a3566ce799dac3253c9e95749d5604bb8d652574ebed066bf |