diff --git a/runtype/pytypes.py b/runtype/pytypes.py index 486fc9e..5f07cb6 100644 --- a/runtype/pytypes.py +++ b/runtype/pytypes.py @@ -359,6 +359,7 @@ def __repr__(self): Object = PythonDataType(object) Iter = SequenceType(PythonDataType(collections.abc.Iterable)) +OrderedDict = DictType(PythonDataType(collections.OrderedDict), variance=Variance.Invariant) Sequence = SequenceType(PythonDataType(abc.Sequence)) List = SequenceType(PythonDataType(list), variance=Variance.Invariant) MutableSequence = SequenceType(PythonDataType(abc.MutableSequence), variance=Variance.Invariant) @@ -486,6 +487,7 @@ def cast_from(self, obj): set: Set, frozenset: FrozenSet, dict: Dict, + collections.OrderedDict: OrderedDict, tuple: Tuple, bool: Bool, None: NoneType, @@ -633,6 +635,9 @@ def _to_canon(self, t): return Type[self.to_canon(t)] # TODO test issubclass on t.__args__ return Type + elif origin is collections.OrderedDict: + a, b = args + return OrderedDict[to_canon(a), to_canon(b)] elif isinstance(t, typing._GenericAlias): return self._to_canon(origin)