Whole file

erezsh/runtype

The author described this change as Fix: Added support for typing.Mutable* and more. It counts as a record because the check below fails on the code as it stood at 49b4abfa5 and passes on e42c0a8db, with nothing else changed between the two runs.

Fix saved2023-09-12
Sharing licenceMIT · LICENSE
Change size+24 0

What the code was meant to do, written into the code itself as a save note

Fix: Added support for typing.Mutable* and more

The change

298298 Iter = SequenceType(PythonDataType(collections.abc.Iterable))
299299 List = SequenceType(PythonDataType(list))
300300 Sequence = SequenceType(PythonDataType(abc.Sequence))
301+MutableSequence = SequenceType(PythonDataType(abc.MutableSequence))
301302 Set = SequenceType(PythonDataType(set))
302303 FrozenSet = SequenceType(PythonDataType(frozenset))
304+AbstractSet = SequenceType(PythonDataType(abc.Set))
303305 Dict = DictType(PythonDataType(dict))
304306 Mapping = DictType(PythonDataType(abc.Mapping))
307+MutableMapping = DictType(PythonDataType(abc.MutableMapping))
305308 Tuple = TupleType()
306309 TupleEllipsis = TupleEllipsisType(PythonDataType(tuple))
307310 # Float = PythonDataType(float)
348351
349352 return Constraint(self, predicates)
350353
354+ def __le__(self, other):
355+ if isinstance(other, SequenceType):
356+ return self <= other.base and self <= other.item
357+ return super().__le__(other)
351358
359+
352360 class _DateTime(PythonDataType):
353361 def cast_from(self, obj):
354362 if isinstance(obj, str):
494502 return Tuple
495503 elif t is typing.Mapping: # 3.6
496504 return Mapping
505+ elif t is typing.MutableMapping:
506+ return MutableMapping
497507 elif t is typing.Sequence:
498508 return Sequence
509+ elif t is typing.MutableSequence:
510+ return MutableSequence
499511
500512 if origin is None:
501513 if isinstance(t, typing.TypeVar):
538550 elif origin is abc.Mapping or origin is typing.Mapping:
539551 k, v = args
540552 return Mapping[to_canon(k), to_canon(v)]
553+ elif origin is abc.MutableMapping or origin is typing.MutableMapping:
554+ k, v = args
555+ return MutableMapping[to_canon(k), to_canon(v)]
541556 elif origin is abc.Sequence or origin is typing.Sequence:
542557 x ,= args
543558 return Sequence[to_canon(x)]
559+ elif origin is abc.MutableSequence or origin is typing.MutableSequence:
560+ x ,= args
561+ return MutableSequence[to_canon(x)]
562+ elif origin is abc.MutableSet or origin is typing.MutableSet:
563+ x ,= args
564+ return Set[to_canon(x)]
565+ elif origin is abc.Set or origin is typing.AbstractSet:
566+ x ,= args
567+ return AbstractSet[to_canon(x)]
544568 elif origin is type or origin is typing.Type:
545569 # TODO test issubclass on t.__args__
546570 return PythonDataType(type)

The check that tells the two apart

failpass·tests/test_basic.py::TestIsa::test_issubclass_mutable

Check file tests/test_basic.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it49b4abfa594ffee264a67ca48c70c5e40bb6e2b5
Broken version dated2023-09-07
Moduleruntype.pytypes
Units changedTypeCaster, _String
Fingerprint5d96a221dd5912eb
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in erezsh/runtype