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

Comments

@ilevkivskyi
Copy link
Collaborator

commented Dec 3, 2016

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

This comment has been minimized.

Copy link
Member

commented Dec 3, 2016

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

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 3, 2016

@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

This comment has been minimized.

Copy link
Member

commented Dec 3, 2016

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

gvanrossum added a commit to python/peps that referenced this issue Dec 5, 2016
variable __annotations__ should be ordered (#151)
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
Projects
None yet
2 participants
You can’t perform that action at this time.