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:

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.5.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplestr-0.5.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

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

Hashes for simplestr-0.5.0.tar.gz
Algorithm Hash digest
SHA256 48181febdc823b396e8aa1a2430c39a6b03c043d02750d0a2be824e82877bbdd
MD5 4ed7815cdc58ed614a423281fa63ad77
BLAKE2b-256 9403b81c32ba928c3e63c175b0a103646ad083caafbbe3cf9c73a2a33f869900

See more details on using hashes here.

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

Hashes for simplestr-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7e4713b88762c6e798901acfbaca84e444ee8f95f2122420327d022c33217e5
MD5 d7fcdfebbae6aadd897720c4b2f45190
BLAKE2b-256 ea85f9358fe0106d54a55836bab6449c1d322f4618f5563778044ccb35011b4e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.1

2 files

0.4

2 files

0.3

2 files

0.2

2 files

0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page