-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix meet_types
for literal and instance
#19605
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
The first operator failure seems like a bug in typeshed to me: python/typeshed#9004 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hm, the from typing import Literal, cast
type PDDatetimeUnitOptions = Literal["s", "ms", "ns"]
time_unit = cast(PDDatetimeUnitOptions, "s") # [redundant-cast] Is the current behavior of emitting redundant cast here intentional? It seems formally incorrect, since In comparison, |
This comment has been minimized.
This comment has been minimized.
2f41cab
to
35ec958
Compare
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: prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/task_worker.py:370: error: Argument 1 to "submit" of "Executor" has incompatible type "Callable[[Callable[_P, _T], **_P], _T]"; expected "Callable[[Callable[[Task[P, R], Optional[UUID], Optional[TaskRun], Optional[dict[str, Any]], Union[PrefectFuture[Any], Any, Iterable[Union[PrefectFuture[Any], Any]], None], Literal['state', 'result'], Optional[dict[str, set[RunInput]]], Optional[dict[str, Any]]], Union[R, State[Any], None]], Task[[VarArg(Any), KwArg(Any)], Any], UUID, TaskRun, dict[Any, Any], list[Any], str, Optional[Any]], Union[Any, State[Any], None]]" [arg-type]
pyinstrument (https://github.com/joerick/pyinstrument)
- pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'disabled', 'strict'] | float | bool | None]"; expected "float" [arg-type]
+ pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'strict'] | float | str | bool | None]"; expected "float" [arg-type]
- pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'disabled', 'strict'] | float | bool | None]"; expected "Literal['enabled', 'disabled', 'strict']" [arg-type]
+ pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'strict'] | float | str | bool | None]"; expected "Literal['enabled', 'disabled', 'strict']" [arg-type]
- pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'disabled', 'strict'] | float | bool | None]"; expected "bool | None" [arg-type]
+ pyinstrument/context_manager.py:40: error: Argument 1 to "Profiler" has incompatible type "**dict[str, Literal['enabled', 'strict'] | float | str | bool | None]"; expected "bool | None" [arg-type]
operator (https://github.com/canonical/operator)
+ ops/model.py:831: error: Unsupported operand types for - ("set[tuple[Literal['tcp', 'udp', 'icmp'], int | None]]" and "set[tuple[str, int] | tuple[Literal['tcp', 'udp', 'icmp'], int | None]]") [operator]
+ ops/model.py:833: error: Incompatible types in assignment (expression has type "str", variable has type "Literal['tcp', 'udp', 'icmp']") [assignment]
strawberry (https://github.com/strawberry-graphql/strawberry)
- strawberry/codegen/query_codegen.py:476: error: Redundant cast to "Literal['query', 'mutation', 'subscription']" [redundant-cast]
discord.py (https://github.com/Rapptz/discord.py)
- discord/app_commands/transformers.py:139: error: Incompatible types in assignment (expression has type "list[dict[str, Any]]", target has type "str | int") [assignment]
+ discord/app_commands/transformers.py:139: error: Incompatible types in assignment (expression has type "list[dict[str, Any]]", target has type "bool | str | int") [assignment]
- discord/app_commands/transformers.py:141: error: Incompatible types in assignment (expression has type "list[int]", target has type "str | int") [assignment]
+ discord/app_commands/transformers.py:141: error: Incompatible types in assignment (expression has type "list[int]", target has type "bool | str | int") [assignment]
- discord/app_commands/transformers.py:149: error: Incompatible types in assignment (expression has type "int | float", target has type "str | int") [assignment]
+ discord/app_commands/transformers.py:149: error: Incompatible types in assignment (expression has type "int | float", target has type "bool | str | int") [assignment]
- discord/app_commands/transformers.py:151: error: Incompatible types in assignment (expression has type "int | float", target has type "str | int") [assignment]
+ discord/app_commands/transformers.py:151: error: Incompatible types in assignment (expression has type "int | float", target has type "bool | str | int") [assignment]
dedupe (https://github.com/dedupeio/dedupe)
- dedupe/api.py:1547: error: Redundant cast to "Literal['match', 'distinct']" [redundant-cast]
xarray (https://github.com/pydata/xarray)
- xarray/coding/times.py: note: In function "resolve_time_unit_from_attrs_dtype":
- xarray/coding/times.py:1420: error: Redundant cast to "Literal['s', 'ms', 'us', 'ns']" [redundant-cast]
- xarray/coding/times.py:1433: error: Redundant cast to "Literal['s', 'ms', 'us', 'ns']" [redundant-cast]
- xarray/coding/times.py: note: In member "decode" of class "CFTimedeltaCoder":
- xarray/coding/times.py:1537: error: Redundant cast to "Literal['s', 'ms', 'us', 'ns']" [redundant-cast]
|
Fixes #19560
is_proper_subtype(Literal?, Literal)
now always returnsFalse
;is_subtype
retains original behavior.meet_types
with special casing to carry overlast_known_value
correctly.Currently, one unit test still fails, as an "unreachable" with match-case is not raises