Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed unordered dict
  • Loading branch information
ilevkivskyi committed Sep 11, 2016
commit ce6aa0da7e2de1f1ae4dfd4d064a47eeca5ce79a
9 changes: 4 additions & 5 deletions src/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ def new_user(user_class: Type[U]) -> U:


def _make_nmtuple(name, types):
nm_tpl = collections.namedtuple(name, [n for n in types])
nm_tpl = collections.namedtuple(name, [n for n, t in types])
nm_tpl._field_types = types
try:
nm_tpl.__module__ = sys._getframe(2).f_globals.get('__name__', '__main__')
Expand All @@ -1818,7 +1818,7 @@ def __new__(cls, typename, bases, ns, *, _root=False):
if _root:
return super().__new__(cls, typename, bases, ns)
types = ns.get('__annotations__', {})
return _make_nmtuple(typename, types)
return _make_nmtuple(typename, types.items())

class NamedTuple(metaclass=NamedTupleMeta, _root=True):
"""Typed version of namedtuple.
Expand All @@ -1842,8 +1842,7 @@ class Employee(NamedTuple):
"""

def __new__(self, typename, fields):
types = dict(fields)
return _make_nmtuple(typename, types)
return _make_nmtuple(typename, fileds)
else:
def NamedTuple(typename, fields):
"""Typed version of namedtuple.
Expand All @@ -1861,7 +1860,7 @@ def NamedTuple(typename, fields):
are in the _fields attribute, which is part of the namedtuple
API.)
"""
return _make_nmtuple(typename, dict(fields))
return _make_nmtuple(typename, fields)


def NewType(name, tp):
Expand Down