[issue19979] Missing nested scope vars in class scope (bis)

Ethan Furman report at bugs.python.org
Mon May 19 05:08:20 CEST 2014


Ethan Furman added the comment:

Terry remarked:
---------------
> I am puzzled by the opening statement there that
>
>   from enum import Enum  # I added this as necessary
>   class Season(Enum):
>       SPRING = Season()
>
> "works beautifully" at top level as it indeed raises
> NameError: name 'Season' is not defined

Pay close attention to the line just before that example:

> I tried having the metaclass insert an object into the custom dict
> (aka namespace) returned by __prepare__; this object has the same
> name as the to-be-created class.

It does not raise a NameError because the name was injected via the metaclass __prepare__ method.  (Or did at that time -- I don't think that bit of cleverness made the final cut.)

As far as this enhancement request goes, I think the compatibility break is likely too large to have it in the 3.x series.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19979>
_______________________________________


More information about the Python-bugs-list mailing list