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

Fix type narrowing in lambda expressions #16407

Merged
merged 1 commit into from
Nov 4, 2023

Conversation

ilevkivskyi
Copy link
Member

Fixes #4297

Fix is straightforward: without properly pushing lambda expression on the stack, the previous fix @JukkaL added for nested functions doesn't work for lambdas (it thinks that we are at global scope).

Copy link
Contributor

github-actions bot commented Nov 4, 2023

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

openlibrary (https://github.com/internetarchive/openlibrary)
+ openlibrary/plugins/upstream/utils.py:813: error: Unused "type: ignore" comment  [unused-ignore]

jax (https://github.com/google/jax)
+ jax/_src/interpreters/pxla.py:2117: error: Unused "type: ignore" comment  [unused-ignore]

operator (https://github.com/canonical/operator)
+ ops/testing.py:1741: error: Unused "type: ignore" comment  [unused-ignore]

spark (https://github.com/apache/spark)
+ python/pyspark/sql/pandas/types.py:775: error: Unused "type: ignore" comment  [unused-ignore]
+ python/pyspark/sql/pandas/types.py:1032: error: Unused "type: ignore" comment  [unused-ignore]

discord.py (https://github.com/Rapptz/discord.py)
- discord/player.py:578: error: "None" not callable  [misc]
- discord/player.py:586: error: "None" not callable  [misc]
- discord/player.py:586: error: Argument 2 to "_probe_codec_fallback" of "FFmpegOpusAudio" has incompatible type "str | None"; expected "str"  [arg-type]
- discord/scheduled_event.py:654: error: Item "None" of "Snowflake | None" has no attribute "id"  [union-attr]
- discord/state.py:1101: error: Argument 1 to "store_emoji" of "ConnectionState" has incompatible type "Guild | None"; expected "Guild"  [arg-type]
- discord/state.py:1114: error: Argument 1 to "store_sticker" of "ConnectionState" has incompatible type "Guild | None"; expected "Guild"  [arg-type]
- discord/guild.py:3926: error: Item "datetime" of "Snowflake | datetime" has no attribute "id"  [union-attr]
- discord/client.py:2167: error: Item "datetime" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/client.py:2167: error: Item "None" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/abc.py:1787: error: Item "datetime" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/abc.py:1787: error: Item "None" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/abc.py:1789: error: Item "datetime" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/abc.py:1789: error: Item "None" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/abc.py:1793: error: Item "datetime" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/abc.py:1793: error: Item "None" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/abc.py:1797: error: Item "datetime" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]
- discord/abc.py:1797: error: Item "None" of "Snowflake | datetime | None" has no attribute "id"  [union-attr]

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/structured_configs/_implementations.py:3117: error: Argument 1 to "list" has incompatible type "list[str | DataClass_ | Mapping[str, str | Sequence[str] | None]] | None"; expected "Iterable[Any]"  [arg-type]

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@ilevkivskyi ilevkivskyi merged commit 544e6ce into python:master Nov 4, 2023
17 checks passed
@ilevkivskyi ilevkivskyi deleted the fix-lambda-ctx-binder branch November 4, 2023 23:42
JukkaL pushed a commit that referenced this pull request Nov 10, 2023
Fixes #4297

Fix is straightforward: without properly pushing lambda expression on
the stack, the previous fix @JukkaL added for nested functions doesn't
work for lambdas (it thinks that we are at global scope).
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.

Narrowed down types sometimes not propagated to lambda
2 participants