mxndtaylor / aliasing

a small utility library to add aliases to python classes
MIT License
1 stars 0 forks source link

Feature: method to automatically generate alias names adds aliases based on pre-defined strategies #22

Open mxndtaylor opened 3 weeks ago

mxndtaylor commented 3 weeks ago

Describe the solution you'd like

a decorator (something like @auto_alias) that accepts string options, enum flags or boolean parameters (or some combination) that generates aliases, so make these use cases easier:

Describe alternatives you've considered

@valiases with the exact parameters specified but this could get out of hand and turn into a lot of work to support the same use cases all at the same time. It's also static rather than dynamic. I'd need to define it per member based on it's name. The above solution would automatically change to the new aliases based on the new method name if it was ever changed

mxndtaylor commented 3 weeks ago

I think I will also add custom parameter that accepts a lambda with signature Callable[[str], list[str]] so the end user can define their own aliasing via process instead of statically.

This would allow the user to alias their method the same way no matter what it's name was, so if the name was "bar" and we had asked for custom=lambda x: x[0] + x[-1] (so "br" is the only alias) and then we had to change it to "baz" then without any code change, the alias updates to "bz"

mxndtaylor commented 3 weeks ago

added short and sub with follow behavior on a method named foobar:

The real different between short and sub is when applied to methods with leading underscores (_) like _foobar. short will strip them, sub will not: