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: module-level aliases #21

Open
mxndtaylor opened this issue Jun 5, 2024 · 1 comment
Open

Feature: module-level aliases #21

mxndtaylor opened this issue Jun 5, 2024 · 1 comment
Assignees

Comments

@mxndtaylor
Copy link
Owner

Is your feature request related to a problem?

alias and aliased are limited to use inside classes due them being descriptors

Describe the solution you'd like

I'd like to see either another decorator or descriptor that can be used at the module level.

Solutions that I see at the moment, none of which seem ideal:

  • a dummy class that extends module and holds the aliases
    • problem is, when a module is imported, it would not return the dummy class
  • a decorator that actually copies by value instead of reference
    • the current alias implementation only adds a new attribute to a class which references the same thing

Describe alternatives you've considered

I've tried using the existing descriptors and they do not work, I cannot attach the alias to an already existing module
due to them being immutable, and __set_name__ is not called when assigning descriptors outside of a class.

__get__ is also not called when accessing a module's attribute that defines it.

Also... can just do:

def method():
    return 'test'

my_alias = method
@mxndtaylor mxndtaylor self-assigned this Jun 5, 2024
@mxndtaylor
Copy link
Owner Author

mxndtaylor commented Jun 5, 2024

Note, this code block:

def method():
    return 'test'

my_alias = method

assigns my_alias to reference the same function as method, however changes to the method name in the module won't be reflected in my_alias which would be expected by an implementation that adds this feature.


It might not be possible to implement this in the same way that we have the current aliases.

However, maybe we can at least define aliased functions and aliass for them inside classes.

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

No branches or pull requests

1 participant