Check TypeVar restrictions when the expected type is gradual - #4506
Open
alexander-beedie wants to merge 1 commit into
Open
Check TypeVar restrictions when the expected type is gradual#4506alexander-beedie wants to merge 1 commit into
TypeVar restrictions when the expected type is gradual#4506alexander-beedie wants to merge 1 commit into
Conversation
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D115555748. (Because this pull request was imported automatically, there will not be any future comments.) |
|
Diff from mypy_primer, showing the effect of this PR on open source code: egglog-python (https://github.com/egraphs-good/egglog-python)
+ ERROR python/egglog/egraph.py:2358:30-58: `int` is not assignable to upper bound `ComparableAddSub` of type variable `DAG_COST` [bad-specialization]
schemathesis (https://github.com/schemathesis/schemathesis)
+ ERROR src/schemathesis/specs/openapi/operations.py:95:54-103:10: `None` is not assignable to upper bound `ResponsesContainer[Unknown]` of type variable `R` [bad-specialization]
static-frame (https://github.com/static-frame/static-frame)
+ ERROR static_frame/core/index.py:602:34-608:10: `Self@Index` is not assignable to any of constraints `Frame`, `Series`, `Bus`, `Quilt`, `Yarn` of type variable `TContainerAny` [bad-specialization]
+ ERROR static_frame/core/index_hierarchy.py:1359:34-1365:10: `Self@IndexHierarchy` is not assignable to any of constraints `Frame`, `Series`, `Bus`, `Quilt`, `Yarn` of type variable `TContainerAny` [bad-specialization]
pandas (https://github.com/pandas-dev/pandas)
+ ERROR pandas/tests/frame/methods/test_to_csv.py:1420:25-48: Argument `NaTType | Timestamp` is not assignable to parameter `left` with type `Timestamp` in function `pandas._libs.interval.Interval.__init__` [bad-argument-type]
+ ERROR pandas/tests/frame/methods/test_to_csv.py:1421:25-48: Argument `NaTType | Timestamp` is not assignable to parameter `right` with type `Timestamp` in function `pandas._libs.interval.Interval.__init__` [bad-argument-type]
meson (https://github.com/mesonbuild/meson)
+ ERROR mesonbuild/mparser.py:725:36-70: `None` is not assignable to any of constraints `int`, `str`, `bool` of type variable `TV_TokenTypes` [bad-specialization]
+ ERROR mesonbuild/mparser.py:751:33-178: `None` is not assignable to any of constraints `int`, `str`, `bool` of type variable `TV_TokenTypes` [bad-specialization]
+ ERROR unittests/versiontests.py:302:48-49: Argument `Literal[3]` is not assignable to parameter `min` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:303:48-50: Argument `Literal[12]` is not assignable to parameter `max` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:307:48-49: Argument `Literal[5]` is not assignable to parameter `min` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:307:68-70: Argument `Literal[10]` is not assignable to parameter `max` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:310:49-51: Argument `Literal[11]` is not assignable to parameter `min` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:311:49-50: Argument `Literal[4]` is not assignable to parameter `max` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:314:50-51: Argument `Literal[7]` is not assignable to parameter `min` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:315:50-51: Argument `Literal[8]` is not assignable to parameter `max` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:318:50-51: Argument `Literal[5]` is not assignable to parameter `min` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:319:50-52: Argument `Literal[10]` is not assignable to parameter `max` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:322:54-55: Argument `Literal[5]` is not assignable to parameter `min` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
+ ERROR unittests/versiontests.py:327:49-50: Argument `Literal[5]` is not assignable to parameter `min` with type `@_ | None` in function `mesonbuild.utils.universal.Range.__init__` [bad-argument-type]
core (https://github.com/home-assistant/core)
+ ERROR homeassistant/components/miele/sensor.py:209:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:237:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:246:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:274:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:301:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:319:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:340:24-29: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:359:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:377:24-29: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:396:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:422:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:422:54-80: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:448:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:448:54-78: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:476:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:476:54-76: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:506:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:507:17-43: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:507:45-67: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:532:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:533:17-41: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:533:43-65: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:565:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:565:57-81: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:583:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:583:57-81: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:600:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:600:57-81: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:616:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:617:17-52: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:638:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:639:17-47: The type of this argument is unknown [unknown-argument-type]
+ ERROR homeassistant/components/miele/sensor.py:656:29-34: Type of lambda parameter `value` is unknown [implicit-any-lambda]
+ ERROR homeassistant/components/miele/sensor.py:657:17-45: The type of this argument is unknown [unknown-argument-type]
xarray (https://github.com/pydata/xarray)
+ ERROR xarray/core/groupby.py:502:35-72: `T_DataWithCoords` is not assignable to any of constraints `DataArray`, `Dataset` of type variable `T_Xarray` [bad-specialization]
graphql-core (https://github.com/graphql-python/graphql-core)
+ ERROR tests/type/test_validation.py:77:23-30: `GraphQLNamedType` is not assignable to upper bound `GraphQLEnumType | GraphQLInputObjectType | GraphQLInterfaceType | GraphQLList | GraphQLObjectType | GraphQLScalarType | GraphQLUnionType` of type variable `GNT_co` [bad-specialization]
+ ERROR src/graphql/utilities/map_schema_config.py:160:34-59: `GraphQLList[Unknown] | GraphQLNamedType | GraphQLNonNull[Unknown]` is not assignable to upper bound `GraphQLEnumType | GraphQLInputObjectType | GraphQLInterfaceType | GraphQLList | GraphQLObjectType | GraphQLScalarType | GraphQLUnionType` of type variable `GNT_co` [bad-specialization]
django-modern-rest (https://github.com/wemake-services/django-modern-rest)
+ ERROR dmr/internal/io.py:60:17-36: `AsyncIterable[Any]` is not assignable to upper bound `_SupportsAclose` of type variable `_SupportsAcloseT` [bad-specialization]
|
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
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.
Summary
Fixes #3525.
Overview
A gradual annotation on a constructor call silently disabled bound and constraint checking:
Remove the annotation and the error is caught...
Explanation
Applying the hint compares
Container[?T]againstContainer[Any], which pushesAnyinto?T; this was then treated that as a solution and locked in, sox: Tdegraded tox: Anyand accepted anything 👀Solution
An
Anyfrom the expected type says nothing, so it is discarded, leaving the parameter free for argument matching to check normally (note that anAnyfrom an actual argument is still a real solution).Test Plan
All existing unit tests pass, several new tests were added.
Multiple new matches relating to this are now found in the
mypy_primercorpus; I've verified a sample of them, and they appeared to be correct (agreeing withpyright, which flags the same lines).