We can rename class methods at class definition time with a metaclass. This question is not about that.
This is more of a thought experiment, so humour me a little please.
Say I wanted to write two decorators that are used like this:
class SomeClass(object):
@append_A
def some_method( self ):
pass
@append_B
def some_method( self ):
pass
Which would result in SomeClass
having two methods: some_method_A
and some_method_B
Is this possible and if so, can you point me in the right direction?
I've tried changing the frame's f_locals
a few different ways, but the method name still persists.
No, it's not possible to change method names using decorator, as explained in the documentation:
More syntax discussion goes here.
Update
For this purpose you can use the class decorator:
The following usage allows you to define two names for the same method: