Fix python 3.6 namedtuple compatibility

This commit is contained in:
M1ha 2019-06-28 11:09:17 +05:00
parent 8a581f27db
commit 355b8c7321

View File

@ -10,11 +10,9 @@ def namedtuple(*args, **kwargs):
:return: namedtuple class
"""
if sys.version_info < (3, 7):
defaults = kwargs.pop('defaults', {})
defaults = kwargs.pop('defaults', ())
TupleClass = basenamedtuple(*args, **kwargs)
TupleClass.__new__.__defaults__ = (None,) * len(TupleClass._fields)
prototype = TupleClass(*defaults)
TupleClass.__new__.__defaults__ = tuple(prototype)
TupleClass.__new__.__defaults__ = (None,) * (len(TupleClass._fields) - len(defaults)) + tuple(defaults)
return TupleClass
else:
return basenamedtuple(*args, **kwargs)