[Python-Dev] PEP 435: pickling enums created with the functional API

Piotr Duda duda.piotr at gmail.com
Tue May 7 16:48:26 CEST 2013


2013/5/7 Eli Bendersky <eliben at gmail.com>:
>
> 4) Using _getframe(N) here seems like an overkill to me. What we really need
> is just the module in which the current execution currently is (i.e. the
> metaclass's __new__ in our case). Would it make sense to add a new function
> somewhere in the stdlib of 3.4 (in sys or inspect or ...) that just provides
> the current module name? It seems that all Pythons should be able to easily
> provide it, it's certainly a very small subset of the functionality provided
> by walking the callframe stack. This function can then be used for build
> fully qualified names for pickling of Enum and namedtuple. Moreover, it can
> be general even more widely - dynamic class building is quite common in
> Python code, and as Nick mentioned somewhere earlier, the extra power of
> metaclasses in the recent 3.x's will probably make it even more common.

What about adding simple syntax (I proposed this earlier, but no one
commented) that take care of assigning name and module, something
like:

def name = expression

which would be rough equivalent for:

name = expression
name.__name__ = 'name'
name.__module__ = __name__


--
闇に隠れた黒い力
弱い心を操る


More information about the Python-Dev mailing list