Skip to main content

Method aliasing system with argument remapping and optional stub generation

Project description

Reflexsive

ci-release codedev license

A lightweight Python library that enables concise method aliasing with optional argument remapping. Designed for ergonomic command interfaces, alternative method names, and API compatibility layers.


✨ Features

  • Define aliases for class methods with different argument names.
  • Supports instance, static, and class methods.
  • Optional argument renaming per alias.
  • Flexible usage with or without arguments.
  • Stub file (.pyi) generation for autocompletion support.
  • Optional prefixing for namespacing aliases.
  • Strict conflict checking to prevent ambiguous mappings.

🔧 Installation

pip install reflexsive

🚀 Usage

from reflexsive import Reflexsive

class MyAPI(Reflexsive):
    @Reflexsive.alias('short', username='u', password='p')
    def authenticate(self, username, password):
        return f"{username}:{password}"

obj = MyAPI()
print(obj.authenticate('admin', '123'))     # 'admin:123'
print(obj.short('admin', '123'))            # Same result using alias
print(obj.short(u='admin', p='123'))        # Keyword aliasing

⚙️ Configuration Options

When using class A(Reflexsive, ...), you can pass configuration flags:

Option Type Default Description
allow_kwargs_override bool False Allow alias names to override **kwargs
expose_alias_map bool False (Planned) Expose alias map on class
docstring_alias_hints bool True (Planned) Include alias info in docstrings
alias_prefix str None Prefix added to all alias names

Example 1: Without options

class Example(Reflexsive):
    ...

Example 2: With options

class Example(Reflexsive, create_pyi_stub=True, alias_prefix='a_'):
    ...

🧪 Testing

Tests are provided using pytest.\n

Tests cover:

  • Alias mapping (positional and keyword)
  • Class/Static method support
  • Error handling for conflicting or invalid aliases
  • Stub generation
  • Prefix options
  • Edge cases (built-in names, decorator order, etc.)

❗ Exception Types

The library defines the following custom exceptions:

  • AliasNameConflictError: Raised when an alias name conflicts with another method or alias.
  • AliasArgumentError: Raised when alias mappings include invalid or forbidden parameters (e.g., *args).
  • AliasConfigurationError: Raised when invalid configuration options are passed to @aliased_class.

Notes

  • Using classmethod/staticmethod decorators before @alias makes Pylance complain - but does work at runtime

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

reflexsive-0.1.1.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

reflexsive-0.1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file reflexsive-0.1.1.tar.gz.

File metadata

  • Download URL: reflexsive-0.1.1.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for reflexsive-0.1.1.tar.gz
Algorithm Hash digest
SHA256 77faddc78f5cdb49d2c98fb32bb40a262179f381c0a38fe29a4128814c6fc6d3
MD5 89dd2ff26eca83d0b81b729bbd371684
BLAKE2b-256 9807cf3186411dae529a3fc39e54fba03a10d3ce1365ee6d23db796188752f48

See more details on using hashes here.

File details

Details for the file reflexsive-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: reflexsive-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for reflexsive-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e4a5ffcc270bb7fa81167492d2d99091c07f3146a1c6b1069e18312cef2e7b23
MD5 5c6842cfff06a22efb8a8abbd5381a5a
BLAKE2b-256 152530961479c2130076e8ab300ce8245910084405849989bfd1ebbb0aa144f1

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