-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Extend special-case for context-based typevar inference in return position to typevar unions #18976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sterliakov
wants to merge
6
commits into
python:master
Choose a base branch
from
sterliakov:bugfix/gh-17221-typevar-union-context
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Extend special-case for context-based typevar inference in return position to typevar unions #18976
sterliakov
wants to merge
6
commits into
python:master
from
sterliakov:bugfix/gh-17221-typevar-union-context
+33
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ition to typevar unions
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: antidote (https://github.com/Finistere/antidote)
- src/antidote/lib/interface_ext/_provider.py:313: error: Generator has incompatible item type "NewWeight"; expected "Weight" [misc]
- src/antidote/lib/interface_ext/_provider.py:314: error: Argument 2 to "sum" has incompatible type "NewWeight"; expected "Weight" [arg-type]
+ src/antidote/lib/interface_ext/_provider.py:312: error: Argument "weight" to "replace" of "CandidateImplementation[Weight]" has incompatible type "NewWeight"; expected "Weight" [arg-type]
xarray (https://github.com/pydata/xarray)
+ xarray/core/utils.py: note: In function "get":
+ xarray/core/utils.py:503: error: Argument 2 to "get" of "Mapping" has incompatible type "T | None"; expected "V" [arg-type]
+ xarray/conventions.py: note: In function "decode_cf_variables":
+ xarray/conventions.py:410: error: Argument "decode_times" to "decode_cf_variable" has incompatible type "object"; expected "bool | CFDatetimeCoder" [arg-type]
+ xarray/conventions.py:413: error: Argument "decode_timedelta" to "decode_cf_variable" has incompatible type "object"; expected "bool | CFTimedeltaCoder | None" [arg-type]
bidict (https://github.com/jab/bidict)
+ bidict/_base.py: note: In member "_dedup" of class "BidictBase":
+ bidict/_base.py:330:41: error: Argument 2 to "get" of "Mapping" has incompatible type "Literal[MissingT.MISSING]"; expected "VT" [arg-type]
+ bidict/_base.py:331:41: error: Argument 2 to "get" of "Mapping" has incompatible type "Literal[MissingT.MISSING]"; expected "KT" [arg-type]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/clients.py:2428: error: Argument 1 to "get_type_dependency" of "Client" has incompatible type "type[SingleStoreCache[AuthorizationApplication]]"; expected "type[SingleStoreCache[Application]] | type[None]" [arg-type]
operator (https://github.com/canonical/operator)
- ops/_main.py:95: error: Argument 2 to "next" has incompatible type "None"; expected "Storage" [arg-type]
+ ops/_main.py:95: error: Incompatible types in assignment (expression has type "Storage | None", variable has type "Storage") [assignment]
setuptools (https://github.com/pypa/setuptools)
+ setuptools/msvc.py:1442: error: Unused "type: ignore" comment [unused-ignore]
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/datastructures/mixins.py:280: error: Unused "type: ignore" comment [unused-ignore]
+ src/werkzeug/datastructures/mixins.py:280: error: Incompatible types in assignment (expression has type "Union[V, T]", variable has type "V") [assignment]
+ src/werkzeug/datastructures/mixins.py:280: note: Error code "assignment" not covered by "type: ignore" comment
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/monkeypatch.py:293: error: Argument 2 to "get" of "Mapping" has incompatible type "Notset"; expected "V" [arg-type]
+ src/_pytest/monkeypatch.py:307: error: Argument 2 to "get" of "Mapping" has incompatible type "Notset"; expected "V" [arg-type]
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
min
withkey
lambda function and default value when result is Optional #17221.TypeVar
s don't meet the expected type #17553.max()
"tainted" bydefault
#16267.return
statement withnext
andor
#15755.all_equal
recipe causes false arg-type failures #15150.When using context, we can perform some overly optimistic inference when return type is
T1 | T2
. This breaks in important case ofbuiltins.min
whendefault
andkey
are passed, essentially making them always incompatible. This is not the most principled approach, but let's see the primer results.This resolves quite a few issues (some of them duplicates, but some - substantially different),
min
problem was a very popular one... Diff run: sterliakov/mypy-issues#30This PR introduces one major regression. Namely, the following code becomes rejected:
Prior to this PR,
fail1
was rejected butfail2
was accepted. Now both trigger a diagnostic. This problem stems fromMapping.get
definition in typeshed:I don't know why union is used for
default
. This only applies toMapping
with this weird definition,dict
overridesget
to a longer version and works as intended.I haven't yet figured out how to handle this sensibly assuming we don't want to change typeshed definition.