Use two-phase type checking in sequential mode - #21973
Open
ilevkivskyi wants to merge 3 commits into
Open
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: steam.py (https://github.com/Gobot1234/steam.py)
- steam/chat.py:248: error: "fetch_message_reactors" of "ConnectionState" gets multiple values for keyword argument "server_timestamp" [misc]
- steam/chat.py:248: error: "fetch_message_reactors" of "ConnectionState" gets multiple values for keyword argument "ordinal" [misc]
- steam/chat.py:248: error: "fetch_message_reactors" of "ConnectionState" gets multiple values for keyword argument "reaction_name" [misc]
- steam/chat.py:248: error: "fetch_message_reactors" of "ConnectionState" gets multiple values for keyword argument "reaction_type" [misc]
- steam/chat.py:290: error: Too many arguments for "react_to_chat_message" of "ConnectionState" [call-arg]
- steam/chat.py:290: error: "react_to_chat_message" of "ConnectionState" gets multiple values for keyword argument "reaction_type" [misc]
- steam/chat.py:290: error: "react_to_chat_message" of "ConnectionState" gets multiple values for keyword argument "is_add" [misc]
- steam/chat.py:318: error: Too many arguments for "ack_chat_message" of "ConnectionState" [call-arg]
spark (https://github.com/apache/spark)
+ python/pyspark/pandas/frame.py:666: error: Unused "type: ignore" comment [unused-ignore]
+ python/pyspark/pandas/frame.py:666: error: Redundant cast to "InternalFrame" [redundant-cast]
+ python/pyspark/pandas/frame.py:666: note: Error code "redundant-cast" not covered by "type: ignore[has-type]" comment
+ python/pyspark/streaming/context.py:226: error: Incompatible types in assignment (expression has type "StreamingContext", variable has type "None") [assignment]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/runner/runner.py:329: error: Incompatible return value type (got "EventsClient | None", expected "EventsClient") [return-value]
- src/prefect/runner/runner.py:306: error: Cannot determine type of "_scheduled_run_poller" [has-type]
- src/prefect/runner/runner.py:312: error: Cannot determine type of "_scheduled_run_poller" [has-type]
- src/prefect/runner/runner.py:329: error: Cannot determine type of "_event_emitter" [has-type]
- src/prefect/runner/runner.py:670: error: Cannot determine type of "_scheduled_run_poller" [has-type]
- src/prefect/runner/runner.py:672: error: Cannot determine type of "_scheduled_run_poller" [has-type]
- src/prefect/runner/runner.py:686: error: Cannot determine type of "_cancellation_manager" [has-type]
- src/prefect/runner/runner.py:698: error: Cannot determine type of "_scheduled_run_poller" [has-type]
- src/prefect/runner/runner.py:699: error: Cannot determine type of "_scheduled_run_poller" [has-type]
- src/prefect/runner/runner.py:796: error: Cannot determine type of "_runs_task_group" [has-type]
- src/prefect/runner/runner.py:1243: error: Cannot determine type of "_cancellation_manager" [has-type]
- src/prefect/runner/runner.py:1360: error: Cannot determine type of "_event_emitter" [has-type]
- src/prefect/runner/runner.py:1368: error: Cannot determine type of "_event_emitter" [has-type]
operator (https://github.com/canonical/operator)
- ops/lib/__init__.py:86: error: "None" has no attribute "get" [attr-defined]
+ ops/lib/__init__.py:86: error: Item "None" of "Any | None" has no attribute "get" [union-attr]
altair (https://github.com/vega/altair)
+ altair/vegalite/v6/api.py:3997: error: Argument "spec" to "FacetChart" has incompatible type "_EncodingMixin"; expected "SchemaBase | Mapping[str, Any] | UndefinedType" [arg-type]
egglog-python (https://github.com/egraphs-good/egglog-python)
+ python/egglog/builtins.py:259: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/builtins.py:266: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/builtins.py:370: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/builtins.py:377: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/builtins.py:840: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/builtins.py:847: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/builtins.py:967: error: Unused "type: ignore" comment [unused-ignore]
+ python/egglog/builtins.py:973: error: Unused "type: ignore" comment [unused-ignore]
pip (https://github.com/pypa/pip)
+ src/pip/_internal/resolution/resolvelib/candidates.py:410: error: Incompatible types in assignment (expression has type "Version", variable has type "None") [assignment]
+ src/pip/_internal/resolution/resolvelib/candidates.py:411: error: Incompatible return value type (got "None", expected "Version") [return-value]
pandera (https://github.com/pandera-dev/pandera)
- pandera/engines/polars_engine.py:270: error: "type[object]" has no attribute "to_schema" [attr-defined]
+ pandera/api/pandas/array.py:38: error: Unused "type: ignore" comment [unused-ignore]
sympy (https://github.com/sympy/sympy)
+ sympy/matrices/matrixbase.py:3319: error: Unused "type: ignore" comment [unused-ignore]
trio (https://github.com/python-trio/trio)
+ src/trio/_dtls.py:739: error: Incompatible types in assignment (expression has type "tuple[bytes, bytes]", variable has type "None") [assignment]
jax (https://github.com/google/jax)
- jax/_src/array.py:409: error: No overload variant of "asarray" matches argument types "ndarray[tuple[Any, ...], dtype[Any]]", "dtype[Any] | None", "dict[str, bool]" [call-overload]
+ jax/_src/array.py:409: error: No overload variant of "asarray" matches argument types "Any", "dtype[Any] | None", "dict[str, bool]" [call-overload]
git-revise (https://github.com/mystor/git-revise)
+ gitrevise/odb.py:413: error: Redundant cast to "bytes" [redundant-cast]
|
Member
Author
|
@JukkaL as expected, most of the fallout is caused by fine details of how the partial class C:
x = None
@classmethod
def get_x(cls) -> int:
if cls.x is None:
cls.x = int() # This is OK, always allow partial types here
return cls.xfor consistency with the same exception we have for regular methods. So I don't think there is any need for a new flag. Btw, I also fix an off-by-one error to make multi-pass logic consistent between single-phase and two-phase type checking. |
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.
Fixes #21348
This means that (unless local partial types are disabled) we should have identical semantics for all three: sequential (in-process) type-checking, parallel type-checking, and in the daemon.
When reading the relevant code I noticed a bug, when using
-cin parallel mode we do not check implementations in the code passed with-c, fix is quite simple (just reorder writing cache and flushing the errors), so I simply add it here.cc @JukkaL