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_strto generate__str__(self)method@gen_reprto generate__repr__(self)method@gen_eqto generate__eq__(self, other)method@gen_str_reprto generate both__str__(self)and__repr__(self)methods@gen_str_repr_eqto 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simplestr-0.5.0.tar.gz.
File metadata
- Download URL: simplestr-0.5.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48181febdc823b396e8aa1a2430c39a6b03c043d02750d0a2be824e82877bbdd
|
|
| MD5 |
4ed7815cdc58ed614a423281fa63ad77
|
|
| BLAKE2b-256 |
9403b81c32ba928c3e63c175b0a103646ad083caafbbe3cf9c73a2a33f869900
|
File details
Details for the file simplestr-0.5.0-py3-none-any.whl.
File metadata
- Download URL: simplestr-0.5.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e4713b88762c6e798901acfbaca84e444ee8f95f2122420327d022c33217e5
|
|
| MD5 |
d7fcdfebbae6aadd897720c4b2f45190
|
|
| BLAKE2b-256 |
ea85f9358fe0106d54a55836bab6449c1d322f4618f5563778044ccb35011b4e
|