[Python-Dev] Issue #21205: add __qualname__ to generators

Victor Stinner victor.stinner at gmail.com
Thu Jun 12 11:41:22 CEST 2014


2014-06-11 18:17 GMT+02:00 Antoine Pitrou <antoine at python.org>:
> Le 11/06/2014 10:28, Victor Stinner a écrit :
>> (...)
>> Issues describing the problem, I attached a patch implementing my ideas:
>> http://bugs.python.org/issue21205
>>
>> Would you be ok with these (minor) incompatible changes?
>
> +1 from me.
>
> Regards
> Antoine.

I asked myself if this change can cause issues with serialization. The
marshal and pickle modules cannot serialize a generator. Marshal only
supports a few types. For pickle, I found this explanation:
http://peadrop.com/blog/2009/12/29/why-you-cannot-pickle-generators/

So I consider that my change is safe. It changes the representation of
a generator, but repr() is usually only checked in unit tests, tests
can be fixed. It also changes the value of the __name__ attribute if
the name of the function was changed, but I don't think that anyone
relies on it. If you really want the original name of the code object,
you can still get gen.gi_code.co_name.

Another recent change in the Python API was the __wrapped__ attribute
set by functools.wraps(). It is now chain wrapper functions, and I'm
not aware of anyone complaining of such change. So I'm confident in my
change :)

Victor


More information about the Python-Dev mailing list