Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should NamedTuple rely on dict being oredered? #339

Closed
ilevkivskyi opened this issue Dec 3, 2016 · 3 comments
Closed

Should NamedTuple rely on dict being oredered? #339

ilevkivskyi opened this issue Dec 3, 2016 · 3 comments

Comments

@ilevkivskyi
Copy link
Member

Currently, NamedTuple relies on the fact that dict is ordered in Python 3.6. However, (if I remember correctly) it was decided at some point that the ordered nature of dict is a CPython implementation detail. The question is should we explicitly use an OrderedDict instead?

@gvanrossum
Copy link
Member

How exactly does it depend on that? IIRC you can trust that the namespace arg to __new__ is ordered -- either it's a dict and the dict implementation is ordered, or else it's an OrderedDict.

@ilevkivskyi
Copy link
Member Author

@gvanrossum It actually depends on __annotations__ being ordered. The point is that if one writes:

class C:
    x: int
    y: str

then x and y don't appear in the class namespace. Actually, now I am thinking maybe it makes sense to require __annotations__ to be ordered? (Fortunately, PEP 526 is still provisional, so that it could be updated.)

@gvanrossum
Copy link
Member

Yes, esp. since there are no code changes needed.

gvanrossum pushed a commit to python/peps that referenced this issue Dec 5, 2016
Fixes python/typing#339

Following the discussion on python/typing issue (and taking into account that dict in 3.6 is ordered being an implementation detail) it is proposed to make __annotations__ ordered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants