Skip to main content

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:

Metadata

Release files for simplestr 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simplestr 0.5.0
File Size Uploaded
simplestr-0.5.0.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simplestr 0.5.0
File Interpreter ABI Platform
simplestr-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.0 kB

Release files / simplestr-0.5.0.tar.gz

Download URL simplestr-0.5.0.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
48181febdc823b396e8aa1a2430c39a6b03c043d02750d0a2be824e82877bbdd
BLAKE2b-256 checksum
How to use checksums
9403b81c32ba928c3e63c175b0a103646ad083caafbbe3cf9c73a2a33f869900
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / simplestr-0.5.0-py3-none-any.whl

Download URL simplestr-0.5.0-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7e4713b88762c6e798901acfbaca84e444ee8f95f2122420327d022c33217e5
BLAKE2b-256 checksum
How to use checksums
ea85f9358fe0106d54a55836bab6449c1d322f4618f5563778044ccb35011b4e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page