Skip to main content

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

RTD

aliaser provides a tiny metaclass and mixin that let you expose call-perfect method aliases without writing boilerplate forwarders.

Table of Contents

Features

  • @alias decorator to expose a method or property under multiple names.
  • Aliases mixin for runtime helpers, backed by the AliasMeta metaclass.
  • Property and method aliases share the original descriptor – no wrappers.
  • install()/uninstall() helpers manage registration of alias on builtins. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aliaser-1.0.0.dev3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

aliaser-1.0.0.dev3-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file aliaser-1.0.0.dev3.tar.gz.

File metadata

  • Download URL: aliaser-1.0.0.dev3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.9 Windows/11

File hashes

Hashes for aliaser-1.0.0.dev3.tar.gz
Algorithm Hash digest
SHA256 f8916870ac3fee76e9c4d2b32933df2476007a92bb3b2b03f6f0088dfb080ed2
MD5 d428e7ac7c06ed7ad2a4f8c6df60f09d
BLAKE2b-256 fe5cdc747657e31ce2ff6d46dfafb3c22e27a7c902bac601eea55066ce5208e3

See more details on using hashes here.

File details

Details for the file aliaser-1.0.0.dev3-py3-none-any.whl.

File metadata

  • Download URL: aliaser-1.0.0.dev3-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.9 Windows/11

File hashes

Hashes for aliaser-1.0.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 a555660f662fd9d98c0a60485dc3294fc5bd26b763119417ec37cb20bc7e3cf1
MD5 01b2388bee5af7df5f50d329362c7e41
BLAKE2b-256 f331571cd9e15d4812d136bd3ead416aef412df9de0a39d3e43c9b9fe1187dcf

See more details on using hashes here.

Supported by

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