Whole file
ramonhagenaars/typish
The author described this change as “Fix for instance checking with Iterable.”. It counts as a record because the check below fails on the code as it stood at d682379e4 and passes on 99e63555a, with nothing else changed between the two runs.
Projectramonhagenaars/typish
Fix saved2020-02-29
Sharing licenceMIT · LICENSE
Change size+9 −1
What the code was meant to do, written into the code itself as a save note
Fix for instance checking with Iterable.
The change
| 184 | 184 | if info_generic_type is tuple: | |
| 185 | 185 | # Special case. | |
| 186 | 186 | result = _subclass_of_tuple(cls_args, info_args) | |
| 187 | + | elif get_origin(cls) is tuple and info_generic_type is typing.Iterable: | |
| 188 | + | # Another special case. | |
| 189 | + | args = get_args(cls) | |
| 190 | + | if len(args) > 1 and args[1] is ...: | |
| 191 | + | args = [args[0]] | |
| 192 | + | ancestor = common_ancestor_of_types(*args) | |
| 193 | + | result = subclass_of(typing.Iterable[ancestor], | |
| 194 | + | typing.Iterable[args[0]]) | |
| 187 | 195 | elif info_generic_type is typing.Union: | |
| 188 | 196 | # Another special case. | |
| 189 | 197 | result = _subclass_of_union(cls, info_args) | |
| 190 | - | elif (cls_generic_type == info_generic_type and cls_args | |
| 198 | + | elif (subclass_of(cls_generic_type, info_generic_type) and cls_args | |
| 191 | 199 | and len(cls_args) == len(info_args)): | |
| 192 | 200 | for tup in zip(cls_args, info_args): | |
| 193 | 201 | if not subclass_of(*tup): |
The check that tells the two apart
fail→pass·tests/test_instance_of.py::TestInstanceOf::test_instance_of_iterable
Check file tests/test_instance_of.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 itd682379e4221e6e3ff555840019f1a6069f5c98e
Broken version dated2019-11-23
Moduletypish._functions
Units changed_subclass_of_generic
Fingerprint54b4b430a6cc985a
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 ramonhagenaars/typish
- 2020-10-07get_origin