Skip to main content

reprit

In what follows python is an alias for python3.7 or pypy3.7 or any later version (python3.8, pypy3.8 and so on).

Installation

Install the latest pip & setuptools packages versions

python -m pip install --upgrade pip setuptools

User

Download and install the latest stable version from PyPI repository

python -m pip install --upgrade reprit

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/reprit.git
cd reprit

Install

python setup.py install

Usage

Let's suppose we are defining a class and we want to have __repr__, that:

  1. Includes parameters involved in instance creation. For simple cases it should be possible to copy string & paste in some place (e.g. REPL session) and have similar object definition with as less work as possible. This helps a lot during debugging, logging, in failed test cases with randomly generated data, etc.
  2. In case of signature change method should handle this automatically for simple cases like renaming/removing/changing order of parameters.

This can be done like

>>> from reprit.base import generate_repr
>>> class DummyContainer:
...     def __init__(self, positional, *variadic_positional, keyword_only, **variadic_keyword):
...         self.positional = positional
...         self.variadic_positional = variadic_positional
...         self.keyword_only = keyword_only
...         self.variadic_keyword = variadic_keyword
...
...     __repr__ = generate_repr(__init__)

after that

>>> DummyContainer(range(10), 2, 3, keyword_only='some', a={'sample': 42})
DummyContainer(range(0, 10), 2, 3, keyword_only='some', a={'sample': 42})

or for a class with avoidance of built-in names clash & private'ish attributes & both

>>> from reprit import seekers
>>> from reprit.base import generate_repr
>>> class State:
...     def __init__(self, id_, name, zip_):
...         self.id = id_
...         self._name = name
...         self._zip = zip_
...
...     __repr__ = generate_repr(__init__,
...                              field_seeker=seekers.complex_)

after that

>>> State(1, 'Alabama', 36016)
State(1, 'Alabama', 36016)

We can also tell to skip unspecified optional parameters

>>> from reprit.base import generate_repr
>>> class Employee:
...     def __init__(self, name, email=None, manager=None):
...         self.name = name
...         self.email = email
...         self.manager = manager
... 
...     __repr__ = generate_repr(__init__,
...                              skip_defaults=True)

After that

>>> Employee('John Doe')
Employee('John Doe')
>>> Employee('John Doe',
...          manager=Employee('Jane Doe'))
Employee('John Doe', manager=Employee('Jane Doe'))
>>> Employee('John Doe', 'johndoe@company.com', Employee('Jane Doe'))
Employee('John Doe', 'johndoe@company.com', Employee('Jane Doe'))

Note: this method doesn't automatically handle changes during runtime (e.g. if someone deletes instance field or replaces __init__/__new__ method implementation), in this case user should update __repr__ method as well.

Development

Bumping version

Preparation

Install bump2version.

Pre-release

Choose which version number category to bump following semver specification.

Test bumping version

bump2version --dry-run --verbose $CATEGORY

where $CATEGORY is the target version number category name, possible values are patch/minor/major.

Bump version

bump2version --verbose $CATEGORY

This will set version to major.minor.patch-alpha.

Release

Test bumping version

bump2version --dry-run --verbose release

Bump version

bump2version --verbose release

This will set version to major.minor.patch.

Running tests

Install dependencies

python -m pip install -r requirements-tests.txt

Plain

pytest

Inside Docker container:

  • with CPython
    docker-compose --file docker-compose.cpython.yml up
    
  • with PyPy
    docker-compose --file docker-compose.pypy.yml up
    

Bash script:

  • with CPython

    ./run-tests.sh
    

    or

    ./run-tests.sh cpython
    
  • with PyPy

    ./run-tests.sh pypy
    

PowerShell script:

  • with CPython
    .\run-tests.ps1
    
    or
    .\run-tests.ps1 cpython
    
  • with PyPy
    .\run-tests.ps1 pypy
    

Metadata

Release files for reprit 0.9.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 reprit 0.9.0
File Size Uploaded
reprit-0.9.0.tar.gz 10.9 kB Details

Built distribution (wheel)

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

Total release size: 21.1 kB

Release files / reprit-0.9.0.tar.gz

Download URL reprit-0.9.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
17e9e04679dfc1d1dcd6d945c5d0c51f72272a90343a39c62fa478622b651180
BLAKE2b-256 checksum
How to use checksums
d7dd46a26d61504fed6702c67036a2ea7809a44319f1c64552776c3f9145c73d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / reprit-0.9.0-py3-none-any.whl

Download URL reprit-0.9.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f8053dacf95b3e38c60dc0204d6010ae6548a81d92197701876f1363576dcdb
BLAKE2b-256 checksum
How to use checksums
ffbbdbe079d4e9e15c726b5896b4f52081e8b7025efea9fbc31837c0eacfcc02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

0.0.0

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