[Python-ideas] Fwd: Define a method or function attribute outside of a class with the dot operator
rosuav at gmail.com
Fri Feb 10 10:34:36 EST 2017
On Sat, Feb 11, 2017 at 2:25 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> If I'm reading this right, you want this behaviour:
> class Spam:
> def Spam.func(self): pass
> assert 'Spam.func' not in Spam.__dict__
> assert 'func' in Spam.__dict__
> assert Spam.func.__name__ == 'Spam.func'
> assert Spam.func.__qualname__ == 'Spam.Spam.func'
> If that's the case, I can only ask... what advantage do you see from
> this? Because I can see plenty of opportunity for confusion, and no
I might be wrong about the __name__; that was a response that came
from the massively extensive research of "hmm, I think this would be
what I'd do". It seems the simplest way to cope with the many
possibilities; having __name__ be "func" would work in the dot form,
but not others. But that's bikeshedding.
More information about the Python-ideas