mxndtaylor / aliasing

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

Feature: module-level aliases #21

Open mxndtaylor opened 4 months ago

mxndtaylor commented 4 months ago

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:

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 commented 4 months ago

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.