Skip to content

runtype does not properly handle OrderedDict #73

@27359794

Description

@27359794

Hi, thanks for this library!

First issue: runtype.issubclass disagrees with the built-in issubclass here:

>>> issubclass(collections.OrderedDict, dict)
True
>>> runtype.issubclass(collections.OrderedDict, dict)
False

Second issue: runtype.issubclass does not handle an OrderedDict with type parameters:

>>> issubclass(collections.OrderedDict[str, str], dict)
True
>>> runtype.issubclass(collections.OrderedDict[str, str], dict)
Traceback (most recent call last):
  File "<bla>/site-packages/runtype/pytypes.py", line 637, in to_canon
    return self.cache[t]
           ~~~~~~~~~~^^^
KeyError: collections.OrderedDict[str, str]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<bla>/site-packages/runtype/pytypes.py", line 640, in to_canon
    res = _type_cast_mapping[t]
          ~~~~~~~~~~~~~~~~~~^^^
KeyError: collections.OrderedDict[str, str]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<bla>/site-packages/runtype/validation.py", line 65, in issubclass
    return is_subtype(t1, t2)
           ^^^^^^^^^^^^^^^^^^
  File "<bla>/site-packages/runtype/validation.py", line 23, in is_subtype
    ct1 = type_caster.to_canon(t1)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "<bla>//site-packages/runtype/pytypes.py", line 642, in to_canon
    res = self._to_canon(t)
          ^^^^^^^^^^^^^^^^^
  File "<bla>/site-packages/runtype/pytypes.py", line 633, in _to_canon
    raise NotImplementedError("No support for type:", t)
NotImplementedError: ('No support for type:', collections.OrderedDict[str, str])

Environment: Python 3.12, runtype version 0.5.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions