Skip to content
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

Changed union creation logic to retain (rather than elide) redundant … #8396

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

erictraut
Copy link
Collaborator

…literals in some cases. In particular, for type expressions that explicitly include literals along with their non-literal counterpart like Literal[1] | int. Retaining these redundant subtypes can be useful for language server features like completion suggestions. This addresses #8392.

…literals in some cases. In particular, for type expressions that explicitly include literals along with their non-literal counterpart like `Literal[1] | int`. Retaining these redundant subtypes can be useful for language server features like completion suggestions. This addresses #8392.
Copy link
Contributor

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

xarray (https://github.com/pydata/xarray)
-   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:385:59 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None" in function "open_mfdataset"
+   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:385:59 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "T_Chunks" in function "open_mfdataset"
-     Type "dict[str, float]" is incompatible with type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None"
+     Type "dict[str, float]" is incompatible with type "T_Chunks"
-   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:391:63 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None" in function "open_mfdataset"
+   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:391:63 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "T_Chunks" in function "open_mfdataset"
-     Type "dict[str, float]" is incompatible with type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None"
+     Type "dict[str, float]" is incompatible with type "T_Chunks"
-   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:407:59 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None" in function "open_mfdataset"
+   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:407:59 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "T_Chunks" in function "open_mfdataset"
-     Type "dict[str, float]" is incompatible with type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None"
+     Type "dict[str, float]" is incompatible with type "T_Chunks"
-   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:413:63 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None" in function "open_mfdataset"
+   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:413:63 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "T_Chunks" in function "open_mfdataset"
-     Type "dict[str, float]" is incompatible with type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None"
+     Type "dict[str, float]" is incompatible with type "T_Chunks"
-   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:443:61 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None" in function "open_mfdataset"
+   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:443:61 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "T_Chunks" in function "open_mfdataset"
-     Type "dict[str, float]" is incompatible with type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None"
+     Type "dict[str, float]" is incompatible with type "T_Chunks"
-   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:455:61 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None" in function "open_mfdataset"
+   /tmp/mypy_primer/projects/xarray/asv_bench/benchmarks/dataset_io.py:455:61 - error: Argument of type "dict[str, float]" cannot be assigned to parameter "chunks" of type "T_Chunks" in function "open_mfdataset"
-     Type "dict[str, float]" is incompatible with type "str | int | tuple[int, ...] | Mapping[Any, T_ChunkDim] | None"
+     Type "dict[str, float]" is incompatible with type "T_Chunks"

bokeh (https://github.com/bokeh/bokeh)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)
+       "Nullable[Any]" is incompatible with "None"
-       "Nullable[Any]" is incompatible with "None" (reportArgumentType)
+       "Nullable[Any]" is incompatible with type "Auto" (reportArgumentType)

Tanjun (https://github.com/FasterSpeeding/Tanjun)
-     Parameter type is "Unknown | str" (reportUnknownParameterType)
+     Parameter type is "Unknown | str | Literal['ok']" (reportUnknownParameterType)
-     Type of "result" is "(event: Unknown | str) -> Coroutine[Any, Any, None]" (reportUnknownVariableType)
+     Type of "result" is "(event: Unknown | str | Literal['ok']) -> Coroutine[Any, Any, None]" (reportUnknownVariableType)
-     Argument type is "(event: Unknown | str) -> Coroutine[Any, Any, None]" (reportUnknownArgumentType)
+     Argument type is "(event: Unknown | str | Literal['ok']) -> Coroutine[Any, Any, None]" (reportUnknownArgumentType)
-     Parameter type is "Unknown | str" (reportUnknownParameterType)
+     Parameter type is "Unknown | str | Literal['ok']" (reportUnknownParameterType)
-     Type of "result" is "(event: Unknown | str) -> Coroutine[Any, Any, None]" (reportUnknownVariableType)
+     Type of "result" is "(event: Unknown | str | Literal['ok']) -> Coroutine[Any, Any, None]" (reportUnknownVariableType)
-     Argument type is "(event: Unknown | str) -> Coroutine[Any, Any, None]" (reportUnknownArgumentType)
+     Argument type is "(event: Unknown | str | Literal['ok']) -> Coroutine[Any, Any, None]" (reportUnknownArgumentType)
-     Parameter type is "Unknown | str" (reportUnknownParameterType)
+     Parameter type is "Unknown | str | Literal['ok']" (reportUnknownParameterType)
-     Type of "result" is "(event: Unknown | str) -> Coroutine[Any, Any, None]" (reportUnknownVariableType)
+     Type of "result" is "(event: Unknown | str | Literal['ok']) -> Coroutine[Any, Any, None]" (reportUnknownVariableType)
-     Argument type is "(event: Unknown | str) -> Coroutine[Any, Any, None]" (reportUnknownArgumentType)
+     Argument type is "(event: Unknown | str | Literal['ok']) -> Coroutine[Any, Any, None]" (reportUnknownArgumentType)
-     Parameter type is "Unknown | str" (reportUnknownParameterType)
+     Parameter type is "Unknown | str | Literal['ok']" (reportUnknownParameterType)
-     Type of "result" is "(event: Unknown | str) -> Coroutine[Any, Any, None]" (reportUnknownVariableType)
+     Type of "result" is "(event: Unknown | str | Literal['ok']) -> Coroutine[Any, Any, None]" (reportUnknownVariableType)
-     Argument type is "(event: Unknown | str) -> Coroutine[Any, Any, None]" (reportUnknownArgumentType)
+     Argument type is "(event: Unknown | str | Literal['ok']) -> Coroutine[Any, Any, None]" (reportUnknownArgumentType)

@erictraut erictraut merged commit 96ee9c6 into main Jul 12, 2024
18 checks passed
@erictraut erictraut deleted the issue-8392-2 branch July 12, 2024 16:54
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.

1 participant