[Python-Dev] PEP 520: Ordered Class Definition Namespace

Eric Snow ericsnowcurrently at gmail.com
Wed Jun 8 10:17:28 EDT 2016


On Wed, Jun 8, 2016 at 12:07 AM, Franklin? Lee
<leewangzhong+python at gmail.com> wrote:
> On Jun 7, 2016 8:52 PM, "Eric Snow" <ericsnowcurrently at gmail.com> wrote:
>> * the default class *definition* namespace is now ``OrderdDict``
>> * the order in which class attributes are defined is preserved in the
>
> By using an OrderedDict, names are ordered by first definition point, rather
> than location of the used definition.
>
> For example, the definition order of the following will be "x, y", even
> though the definitions actually bound to the name are in order "y, x".
>         class C:
>             x = 0
>             def y(self): return 'y'
>             def x(self): return 'x'
>
> Is that okay?

In practice that will seldom be an issue.  In the few cases where it
could possibly be a problem, the class may explicitly set
__definition_order__.

-eric


More information about the Python-Dev mailing list