Skip to content

Infer constraints eagerly if actual is Any #19190

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

Merged
merged 1 commit into from
Jun 1, 2025

Conversation

ilevkivskyi
Copy link
Member

Fixes #8829

This case is more common in 1.16 due to some changes in binder, so it would be good to fix it. My fix may be a bit naive, but if mypy_primer looks good, I think it should be OK.

Copy link
Contributor

github-actions bot commented Jun 1, 2025

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

typeshed-stats (https://github.com/AlexWaygood/typeshed-stats): 1.30x slower (72.8s -> 94.5s in single noisy sample)

nox (https://github.com/wntrblm/nox): 1.32x slower (24.9s -> 32.7s in single noisy sample)

psycopg (https://github.com/psycopg/psycopg)
+ tests/types/test_range.py:131: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/types/test_range.py:179: error: Unused "type: ignore" comment  [unused-ignore]

zulip (https://github.com/zulip/zulip)
- zerver/lib/soft_deactivation.py:74: error: Need type annotation for "event_last_message_id"  [var-annotated]
- zerver/actions/invites.py:446: error: Need type annotation for "realm_id"  [var-annotated]
- zerver/actions/invites.py:449: error: Need type annotation for "referrer"  [var-annotated]
- zerver/views/video_calls.py:374: error: "Never" has no attribute "text"  [attr-defined]
- zerver/views/video_calls.py:377: error: "Never" has no attribute "text"  [attr-defined]
- zerver/views/video_calls.py:397: error: "Never" has no attribute "text"  [attr-defined]
- zerver/webhooks/pivotal/view.py:33: error: "Never" has no attribute "text"  [attr-defined]
- zerver/webhooks/pivotal/view.py:34: error: "Never" has no attribute "text"  [attr-defined]
- zerver/webhooks/pivotal/view.py:36: error: "Never" has no attribute "text"  [attr-defined]
- zerver/tests/test_middleware.py:73: error: "Never" has no attribute "get"  [attr-defined]
- zerver/tests/test_middleware.py:78: error: "Never" has no attribute "get"  [attr-defined]
- zerver/tests/test_middleware.py:205: error: "Never" has no attribute "get"  [attr-defined]
- zerver/tests/test_middleware.py:222: error: "Never" has no attribute "get"  [attr-defined]
- zerver/tests/test_middleware.py:232: error: "Never" has no attribute "get"  [attr-defined]
- zerver/tests/test_bots.py:622: error: Need type annotation for "new_bot"  [var-annotated]
- zerver/tests/test_bots.py:2039: error: Need type annotation for "new_bot"  [var-annotated]
- zerver/tests/test_audit_log.py:174: error: "Never" has no attribute "name"  [attr-defined]

xarray (https://github.com/pydata/xarray)
- xarray/computation/apply_ufunc.py: note: In function "apply_variable_ufunc":
- xarray/computation/apply_ufunc.py:838: error: "Never" has no attribute "ndim"  [attr-defined]
- xarray/computation/apply_ufunc.py:841: error: "Never" has no attribute "ndim"  [attr-defined]

cki-lib (https://gitlab.com/cki-project/cki-lib)
- cki_lib/config_tree.py:30: error: Need type annotation for "extend"  [var-annotated]
- cki_lib/yaml.py:93: error: Need type annotation for "include"  [var-annotated]
- cki_lib/messagequeue.py:225: error: Need type annotation for "routing_key"  [var-annotated]
- cki_lib/cki_pipeline.py:443: error: Need type annotation for "values" (hint: "values: list[<type>] = ...")  [var-annotated]

@ilevkivskyi
Copy link
Member Author

mypy_primer looks exactly as expected.

@hauntsaninja hauntsaninja merged commit a16521f into python:master Jun 1, 2025
19 checks passed
@ilevkivskyi ilevkivskyi deleted the fix-any-union-inference branch June 1, 2025 01:10
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.16 makes more common] Inference of Any against optional type infers Never
2 participants