Skip to content

experiment: mark Mapping and Sequence with disjoint_base#16056

Closed
randolf-scholz wants to merge 1 commit into
python:mainfrom
randolf-scholz:mapping_disjoint_sequence
Closed

experiment: mark Mapping and Sequence with disjoint_base#16056
randolf-scholz wants to merge 1 commit into
python:mainfrom
randolf-scholz:mapping_disjoint_sequence

Conversation

@randolf-scholz

Copy link
Copy Markdown
Contributor

The intersection type Mapping[str, T] & Sequence[T] is non-empty, which can be really annoying for parsing nested data structures. This is an experiment to see what happens when we mark them with @disjoint_base.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/schedules.py:584: error: Subclass of "Sequence[int]" and "float" cannot exist: have distinct disjoint bases  [unreachable]
+ tanjun/schedules.py:585: error: Statement is unreachable  [unreachable]

mkdocs (https://github.com/mkdocs/mkdocs)
+ mkdocs/utils/templates.py:47: error: Subclass of "ExtraScriptValue" and "str" cannot exist: have distinct disjoint bases  [unreachable]

xarray (https://github.com/pydata/xarray)
+ xarray/core/dataset.py:202: error: Class "Dataset" has incompatible disjoint bases  [misc]

@JelleZijlstra

Copy link
Copy Markdown
Member

Overall I think it's worth looking for ways to keep type checkers from considering multiple inheritance scenarios that are very unlikely in practice. Incorrect typeshed stubs might not be the best way though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants