-
-
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
Do not consider bare TypeVar not overlapping with None for reachability analysis #18138
Open
sterliakov
wants to merge
4
commits into
python:master
Choose a base branch
from
sterliakov:bugfix/st-none-typevar-overlap
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Do not consider bare TypeVar not overlapping with None for reachability analysis #18138
sterliakov
wants to merge
4
commits into
python:master
from
sterliakov:bugfix/st-none-typevar-overlap
+115
−42
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
CI failed with the Windows problem I faced multiple times before, the rest is green. Primer diff is amazing this time! Every diff line seems to be an improvement.
|
Diff from mypy_primer, showing the effect of this PR on open source code: jinja (https://github.com/pallets/jinja)
+ src/jinja2/lexer.py:761: error: "object" not callable [operator]
+ src/jinja2/lexer.py:781: error: Incompatible types in "yield" (actual type "Tuple[int, object, str]", expected type "Tuple[int, str, str]") [misc]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/states.py:227: error: Incompatible types in assignment (expression has type "BaseException", variable has type "ResultRecord[Any]") [assignment]
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/search/__init__.py:628:18: error: "Node" has no attribute "children" [attr-defined]
+ sphinx/ext/graphviz.py: note: In function "render_dot":
+ sphinx/ext/graphviz.py:307:9: error: Item "StandaloneHTMLBuilder" of "StandaloneHTMLBuilder | LaTeXBuilder | TexinfoBuilder" has no attribute "_graphviz_warned_dot" [union-attr]
+ sphinx/ext/graphviz.py:307:9: error: Item "LaTeXBuilder" of "StandaloneHTMLBuilder | LaTeXBuilder | TexinfoBuilder" has no attribute "_graphviz_warned_dot" [union-attr]
+ sphinx/ext/graphviz.py:307:9: error: Item "TexinfoBuilder" of "StandaloneHTMLBuilder | LaTeXBuilder | TexinfoBuilder" has no attribute "_graphviz_warned_dot" [union-attr]
schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/metaschema.py: note: In member "save" of class "EnumSchema":
+ schema_salad/metaschema.py:1882:49: error: Argument 2 to "save_relative_uri" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:1886:49: error: Argument "base_url" to "save" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py: note: In member "save" of class "SaladEnumSchema":
+ schema_salad/metaschema.py:5378:51: error: Argument "base_url" to "save" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5381:49: error: Argument 2 to "save_relative_uri" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5385:49: error: Argument "base_url" to "save" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5389:47: error: Argument "base_url" to "save" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5392:51: error: Argument 2 to "save_relative_uri" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5395:50: error: Argument 2 to "save_relative_uri" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5398:50: error: Argument 2 to "save_relative_uri" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5404:26: error: Argument "base_url" to "save" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5411:26: error: Argument "base_url" to "save" has incompatible type "Any | None"; expected "str" [arg-type]
+ schema_salad/metaschema.py:5415:49: error: Argument 2 to "save_relative_uri" has incompatible type "Any | None"; expected "str" [arg-type]
kopf (https://github.com/nolar/kopf)
+ kopf/_kits/webhooks.py:539: error: Item "None" of "Any | None" has no attribute "public_url" [union-attr]
pytest (https://github.com/pytest-dev/pytest)
- src/_pytest/_code/code.py:1071: error: Argument 1 to "from_exception" of "ExceptionInfo" has incompatible type "Optional[BaseException]"; expected "BaseException" [arg-type]
- src/_pytest/_code/code.py:1071: error: Item "None" of "Optional[BaseException]" has no attribute "__traceback__" [union-attr]
- src/_pytest/_code/code.py:1077: error: Argument 1 to "from_exception" of "ExceptionInfo" has incompatible type "Optional[BaseException]"; expected "BaseException" [arg-type]
- src/_pytest/_code/code.py:1077: error: Item "None" of "Optional[BaseException]" has no attribute "__traceback__" [union-attr]
paroxython (https://github.com/laowantong/paroxython)
+ paroxython/flatten_ast.py:401: error: "AST" has no attribute "lineno" [attr-defined]
pandera (https://github.com/pandera-dev/pandera)
- pandera/api/dataframe/model.py:72: error: Unused "type: ignore" comment [unused-ignore]
- pandera/api/dataframe/model.py:77: error: Unused "type: ignore" comment [unused-ignore]
cki-lib (https://gitlab.com/cki-project/cki-lib)
- cki_lib/s3bucket.py:57: error: Item "None" of "Any | None" has no attribute "get_credentials" [union-attr]
PyGithub (https://github.com/PyGithub/PyGithub)
- github/GithubObject.py:315: error: Unused "type: ignore" comment [unused-ignore]
discord.py (https://github.com/Rapptz/discord.py)
- discord/ext/commands/core.py:590: error: Unused "type: ignore" comment [unused-ignore]
- discord/ext/commands/core.py:645: error: Item "object" of the upper bound "Cog | None" of type variable "CogT" has no attribute "cog_command_error" [union-attr]
- discord/ext/commands/core.py:884: error: Item "object" of the upper bound "Cog | None" of type variable "CogT" has no attribute "cog_before_invoke" [union-attr]
- discord/ext/commands/core.py:904: error: Item "object" of the upper bound "Cog | None" of type variable "CogT" has no attribute "cog_after_invoke" [union-attr]
- discord/ext/commands/core.py:1148: error: "type[CogT]" has no attribute "__cog_name__" [attr-defined]
- discord/ext/commands/core.py:1277: error: Item "object" of the upper bound "Cog | None" of type variable "CogT" has no attribute "cog_check" [union-attr]
steam.py (https://github.com/Gobot1234/steam.py)
- steam/app.py:130: error: Argument "game_extra_info" to "CMsgClientGamesPlayedGamePlayed" has incompatible type "NameT"; expected "str" [arg-type]
- steam/ext/commands/commands.py:923: error: Incompatible return value type (got "Command[Any, Any, Any] | MaybeCommandT", expected "MaybeBool | MaybeCommandT") [return-value]
ibis (https://github.com/ibis-project/ibis)
+ ibis/util.py:137: error: Incompatible return value type (got "tuple[()]", expected "tuple[V]") [return-value]
- ibis/selectors.py:708: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice[Any, Any, Any] | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]" [arg-type]
+ ibis/selectors.py:708: error: Argument 1 to "ColumnIndex" has incompatible type "str | int | slice[Any, Any, Any] | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]" [arg-type]
- ibis/expr/types/relations.py:2629: error: Argument 3 to "DropNull" has incompatible type "Sequence[str] | None"; expected "tuple[Value[Any, Columnar], ...] | None" [arg-type]
+ ibis/expr/types/relations.py:2629: error: Argument 3 to "DropNull" has incompatible type "Sequence[str] | str | None"; expected "tuple[Value[Any, Columnar], ...] | None" [arg-type]
+ ibis/backends/sqlite/__init__.py:497: error: Item "None" of "Any | Any | Any | Any | Any | None" has no attribute "schema" [union-attr]
- ibis/backends/duckdb/__init__.py:532: error: Argument 1 to "read_parquet" of "Backend" has incompatible type "str | Any | Path | list[Any] | tuple[Any, ...]"; expected "str | Iterable[str]" [arg-type]
+ ibis/backends/duckdb/__init__.py:532: error: Argument 1 to "read_parquet" of "Backend" has incompatible type "str | Path | Any"; expected "str | Iterable[str]" [arg-type]
- ibis/backends/duckdb/__init__.py:536: error: Argument 1 to "read_csv" of "Backend" has incompatible type "str | Any | Path | list[Any] | tuple[Any, ...]"; expected "str | list[str] | tuple[str]" [arg-type]
+ ibis/backends/duckdb/__init__.py:536: error: Argument 1 to "read_csv" of "Backend" has incompatible type "str | Path | Any"; expected "str | list[str] | tuple[str]" [arg-type]
- ibis/backends/duckdb/__init__.py:538: error: Argument 1 to "read_postgres" of "Backend" has incompatible type "str | Any | Path | list[Any] | tuple[Any, ...]"; expected "str" [arg-type]
+ ibis/backends/duckdb/__init__.py:538: error: Argument 1 to "read_postgres" of "Backend" has incompatible type "str | Path | Any"; expected "str" [arg-type]
- ibis/backends/pyspark/__init__.py:962: error: Argument 1 to "read_parquet" of "Backend" has incompatible type "str | Any | Path | list[Any] | tuple[Any, ...]"; expected "str | Path" [arg-type]
- ibis/backends/pyspark/__init__.py:966: error: Argument 1 to "read_csv" of "Backend" has incompatible type "str | Any | Path | list[Any] | tuple[Any, ...]"; expected "str | list[str] | tuple[str]" [arg-type]
+ ibis/backends/pyspark/__init__.py:966: error: Argument 1 to "read_csv" of "Backend" has incompatible type "str | Path | Any"; expected "str | list[str] | tuple[str]" [arg-type]
|
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 #18126.
Simply allowing such intersection was insufficient: existing binder logic widened the type to
T | None
after theis None
check.This PR extends the binder logic to prevent constructing a union type when all conditional branches are reachable and contain no assignments: checking
if isinstance(something, Something)
does not change the type ofsomething
after the end of theif
block.