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.
Projecterezsh/runtype
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
| 298 | 298 | Iter = SequenceType(PythonDataType(collections.abc.Iterable)) | |
| 299 | 299 | List = SequenceType(PythonDataType(list)) | |
| 300 | 300 | Sequence = SequenceType(PythonDataType(abc.Sequence)) | |
| 301 | + | MutableSequence = SequenceType(PythonDataType(abc.MutableSequence)) | |
| 301 | 302 | Set = SequenceType(PythonDataType(set)) | |
| 302 | 303 | FrozenSet = SequenceType(PythonDataType(frozenset)) | |
| 304 | + | AbstractSet = SequenceType(PythonDataType(abc.Set)) | |
| 303 | 305 | Dict = DictType(PythonDataType(dict)) | |
| 304 | 306 | Mapping = DictType(PythonDataType(abc.Mapping)) | |
| 307 | + | MutableMapping = DictType(PythonDataType(abc.MutableMapping)) | |
| 305 | 308 | Tuple = TupleType() | |
| 306 | 309 | TupleEllipsis = TupleEllipsisType(PythonDataType(tuple)) | |
| 307 | 310 | # Float = PythonDataType(float) | |
| ⋯ | |||
| 348 | 351 | ||
| 349 | 352 | return Constraint(self, predicates) | |
| 350 | 353 | ||
| 354 | + | def __le__(self, other): | |
| 355 | + | if isinstance(other, SequenceType): | |
| 356 | + | return self <= other.base and self <= other.item | |
| 357 | + | return super().__le__(other) | |
| 351 | 358 | ||
| 359 | + | ||
| 352 | 360 | class _DateTime(PythonDataType): | |
| 353 | 361 | def cast_from(self, obj): | |
| 354 | 362 | if isinstance(obj, str): | |
| ⋯ | |||
| 494 | 502 | return Tuple | |
| 495 | 503 | elif t is typing.Mapping: # 3.6 | |
| 496 | 504 | return Mapping | |
| 505 | + | elif t is typing.MutableMapping: | |
| 506 | + | return MutableMapping | |
| 497 | 507 | elif t is typing.Sequence: | |
| 498 | 508 | return Sequence | |
| 509 | + | elif t is typing.MutableSequence: | |
| 510 | + | return MutableSequence | |
| 499 | 511 | ||
| 500 | 512 | if origin is None: | |
| 501 | 513 | if isinstance(t, typing.TypeVar): | |
| ⋯ | |||
| 538 | 550 | elif origin is abc.Mapping or origin is typing.Mapping: | |
| 539 | 551 | k, v = args | |
| 540 | 552 | 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)] | |
| 541 | 556 | elif origin is abc.Sequence or origin is typing.Sequence: | |
| 542 | 557 | x ,= args | |
| 543 | 558 | 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)] | |
| 544 | 568 | elif origin is type or origin is typing.Type: | |
| 545 | 569 | # TODO test issubclass on t.__args__ | |
| 546 | 570 | return PythonDataType(type) | |
The check that tells the two apart
fail→pass·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.