Thanks for the explanation! On Sun, Jun 18, 2017 at 4:00 PM, Chris Angelico <ros...@gmail.com> wrote:
> On Mon, Jun 19, 2017 at 8:47 AM, Alireza Rafiei > <alireza.rafie...@gmail.com> wrote: > >> Hmm. So... after x = f, f.__name__ would be different from x.__name__? > > > > > > Yes. > > There's a couple of major problems with that. The first is that, in > Python, there is *absolutely no difference* between accessing an > object via one form and via another. For example: > > >>> x = object() # or anything else > >>> y = [x, x, x] > >>> z = x > >>> q = {"spam": x} > >>> probably = globals()["x"] > > You can access y[0], z, q["spam"], and (most likely) probably, and > they're all the same thing. Exactly the same object. So there's no way > to do attribute access on that object and get different results. > > The second problem is that the current behaviour is extremely > important. One such place is with function decorators, which > frequently need to know the name of the function being worked on: > > def command(func): > parser.add_parser(func.__name__) > ... > > @command > def spaminate(): > ... > > Inside the decorator, "func.__name__" has to be the name of the > function being decorated ("spaminate"), *not* "func". The function has > an identity and a canonical name. Disrupting that would cause major > difficulties for these kinds of decorators. > > ChrisA > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/