-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Make more type expressions valid in PEP 695 aliases and runtime contexts #17404
Merged
Conversation
This file contains 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
E.g. Callable is declared as a special form in typeshed
Diff from mypy_primer, showing the effect of this PR on open source code: steam.py (https://github.com/Gobot1234/steam.py)
- steam/ext/commands/converters.py:510: error: Incompatible types in assignment (expression has type "object", variable has type "type[T]") [assignment]
+ steam/ext/commands/converters.py:510: error: Incompatible types in assignment (expression has type "<typing special form>", variable has type "type[T]") [assignment]
mypy (https://github.com/python/mypy)
+ mypy/stubgenc.py:736: error: Non-overlapping identity check (left operand type: "type", right operand type: "<typing special form>") [comparison-overlap]
+ mypy/stubgenc.py:736: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-comparison-overlap for more info
Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/annotations.py:1601: error: Incompatible return value type (got "object", expected "type[_T]") [return-value]
+ tanjun/annotations.py:1601: error: Incompatible return value type (got "<typing special form>", expected "type[_T]") [return-value]
- tanjun/annotations.py:1853: error: Incompatible return value type (got "object", expected "type[str]") [return-value]
+ tanjun/annotations.py:1853: error: Incompatible return value type (got "<typing special form>", expected "type[str]") [return-value]
- tanjun/annotations.py:2211: error: Argument 1 to "_annotated" has incompatible type "object"; expected "type[Never]" [arg-type]
+ tanjun/annotations.py:2211: error: Argument 1 to "_annotated" has incompatible type "<typing special form>"; expected "type[Never]" [arg-type]
- tanjun/annotations.py:2273: error: Incompatible return value type (got "object", expected "type[PartialChannel]") [return-value]
+ tanjun/annotations.py:2273: error: Incompatible return value type (got "<typing special form>", expected "type[PartialChannel]") [return-value]
pydantic (https://github.com/samuelcolvin/pydantic)
- pydantic/dataclasses.py:228: error: Incompatible types in assignment (expression has type "tuple[type[StandardDataclass], object]", variable has type "tuple[type[StandardDataclass]]") [assignment]
+ pydantic/dataclasses.py:228: error: Incompatible types in assignment (expression has type "tuple[type[StandardDataclass], <typing special form>]", variable has type "tuple[type[StandardDataclass]]") [assignment]
discord.py (https://github.com/Rapptz/discord.py)
- discord/utils.py:1092: error: "object" has no attribute "__args__" [attr-defined]
+ discord/utils.py:1092: error: "<typing special form>" has no attribute "__args__" [attr-defined]
ibis (https://github.com/ibis-project/ibis)
+ ibis/expr/operations/__init__.py:13: error: Incompatible import of "Any" (imported name has type "type[ibis.expr.operations.reductions.Any]", local name has type "<typing special form>") [assignment]
- ibis/expr/types/logical.py:351: error: "object" not callable [operator]
+ ibis/expr/types/logical.py:351: error: "<typing special form>" not callable [operator]
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:861: error: The type "type[list[Any]]" is not generic and not indexable [misc]
|
All the mypy_primer changes seem fine. Summary of what's changed:
|
I'm waiting for a review until tomorrow. |
jhance
approved these changes
Jun 20, 2024
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.
Previously some type expressions, when used as the value of a PEP 695 type alias or in an expression context, generated errors, even if the code would work at runtime. Improve type inference of types in expression contexts (this includes PEP 695 type aliases) to better reflect runtime behavior.
This is still not perfect, since we don't have precise types for everything in stubs. Use
typing._SpecialForm
as a fallback, as it supports indexing and|
operations, which are supported for types.Also update stubs used in tests to better match typeshed stubs. In particular, provide
_SpecialForm
and defineAny = object()
, similar to typeshed.