Skip to main content

Method aliasing system with argument remapping and optional stub generation

Project description

Reflexsive

ci-release coverage 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.6.post0.tar.gz (21.0 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.6.post0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file reflexsive-0.1.6.post0.tar.gz.

File metadata

  • Download URL: reflexsive-0.1.6.post0.tar.gz
  • Upload date:
  • Size: 21.0 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.6.post0.tar.gz
Algorithm Hash digest
SHA256 2ea5062ac7fb4453b7f4fe62e414af29773937da89fa4bd5dfb55292f47d0d08
MD5 3d6f9200c9408dc162b10ee2bff53125
BLAKE2b-256 1e510b0f52bda21f16fae0231aa940531e1ffff058fd519cb2f6b4d9fd511364

See more details on using hashes here.

File details

Details for the file reflexsive-0.1.6.post0-py3-none-any.whl.

File metadata

File hashes

Hashes for reflexsive-0.1.6.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 73a65e3e1bfc297255223f2daa8a1e42b3a22eaf67908e72661ac60eef3dc80b
MD5 4afd9a2ad841e9ec07dbcc01c523fc8c
BLAKE2b-256 8d60917cecce8374647ecba36c8ccadf11f72f49f4bf0fd458e00a41eb6d11fc

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