Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mxndtaylor opened this issue Jun 8, 2024 · 2 comments · May be fixed by #27
Assignees

Comments

@mxndtaylor
Copy link
Owner

mxndtaylor commented Jun 8, 2024

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:

  • "short", alternatively "sub", which generates sub stringed aliases so aardvark would generate a, aa, aar, aard, etc. could accept an Sequence of ints representing indexs to terminate on, something like short=[1, 5] for aardvark would generate a and aardv.
  • "acronym", acronymizes the member get_my_data_please is given alias gmdp
  • "un_private", removes a single leading underscore if there is only 1 leading, removes any number at the end
  • "un_mangled", removes two or more leading underscores and at most 1 at the end
  • "un_magic", removes all leading and all tailing underscores if two or more exist on both ends
  • "case", accepts strategies for naming conventions
    • camel, pascal, caps, kebab, title, sentence, snake, macro, flat, upper, cobol
    • "insensitive" or "all" or something that generates all of them
    • for now, assumes snake_case, but I'll try see about detecting the type of case
    • accepts the parameters autologically? "camelCase" "PascalCase" "kebab-case" etc.

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 mxndtaylor self-assigned this Jun 8, 2024
@mxndtaylor
Copy link
Owner Author

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
Copy link
Owner Author

mxndtaylor commented Jun 10, 2024

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

  • short=True -> aliases f, fo, foo, foob, fooba, foobar
  • short=1 or sub=1 -> aliases f
  • short=[1, 3, 5] or sub=[1, 3, 5] -> aliases f, foo, fooba

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

  • short=True -> aliases f, fo, foo, foob, fooba, foobar
  • short=2 -> aliases fo
  • sub=2 -> aliases _f -- notice the leading underscore
  • short=[1, 3, 5] -> aliases f, foo, fooba
  • sub=[1, 3, 5] -> aliases _, _fo, _foob -- notice the leading underscore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant