Drop-in mix-in + metaclass that let you declare any number of call-perfect aliases for a method with a single decorator or a runtime helper. No boiler-plate forwarders required.
Project description
aliaser
aliaser provides a tiny metaclass and mixin that let you expose call-perfect method aliases without writing boilerplate forwarders.
Table of Contents
Features
@aliasdecorator to expose a method or property under multiple names.Aliasesmixin for runtime helpers, backed by theAliasMetametaclass.- Property and method aliases share the original descriptor – no wrappers.
install()/uninstall()helpers manage registration ofaliasonbuiltins.install()runs automatically on import for drop-in usage.
Installation
Install from PyPI:
pip install aliaser
Or add it to a Poetry project:
poetry add aliaser
Usage
Declaring aliases with @alias
from aliaser import Aliases, alias
class Greeter(Aliases):
@alias('hi', 'sup')
def hello(self):
print("Hello!")
Greeter().hi() # prints "Hello!"
Adding aliases at runtime
Greeter.add_alias('hello', 'howdy')
Greeter().howdy() # also prints "Hello!"
Avoiding the built-ins side effect
Importing the top-level package calls aliaser.install() which registers
alias on builtins. This modifies the global namespace. Call
aliaser.uninstall() to undo the side effect, or import alias from
aliaser.decorator and Aliases from aliaser.mixin directly instead of
importing aliaser.
Development
Clone the repository and install dependencies with Poetry:
poetry install
After making changes you can build the wheel with poetry build. Feel free to
open issues or pull requests on GitHub to discuss improvements.
Supported Python versions
This project requires Python 3.12 or newer.
License
aliaser is distributed under the MIT License.
Project details
Release history Release notifications | RSS feed
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 aliaser-1.0.0.dev4.tar.gz.
File metadata
- Download URL: aliaser-1.0.0.dev4.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.9 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6de263e1c4109c61af19f3c2e16cfc14607fb8b09735f35ea7dd6b3841e304c
|
|
| MD5 |
4529c03dc13a4a00dcdf08c5fd68f2ea
|
|
| BLAKE2b-256 |
44a8ed770d530eba55c1ce21fd47b98cf0a0b28df8cabb7fd4605743bf204575
|
File details
Details for the file aliaser-1.0.0.dev4-py3-none-any.whl.
File metadata
- Download URL: aliaser-1.0.0.dev4-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.9 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e42cdd29ee10bf5429bcadaa016f02fe9b01c2f72c536896490ee693e023ef3
|
|
| MD5 |
9652753ab2142af7a22064ff0e5334db
|
|
| BLAKE2b-256 |
38b0c63e91cd8df5cf7f158fd69a1424404e3073a9b866d113a3f7fc88cd7f9b
|