Skip to content

Preserve gradual guarantee when narrowing Any union via equality#21368

Merged
hauntsaninja merged 4 commits into
python:masterfrom
hauntsaninja:narrowanyunion
Apr 29, 2026
Merged

Preserve gradual guarantee when narrowing Any union via equality#21368
hauntsaninja merged 4 commits into
python:masterfrom
hauntsaninja:narrowanyunion

Conversation

@hauntsaninja

Copy link
Copy Markdown
Collaborator

Fixes #21364

@github-actions

This comment has been minimized.

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LG, couple suggestions.

Comment thread test-data/unit/check-narrowing.test
Comment thread mypy/checker.py
@github-actions

Copy link
Copy Markdown
Contributor

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

cryptography (https://github.com/pyca/cryptography)
- src/cryptography/hazmat/primitives/serialization/ssh.py:1120: error: Argument 16 to "SSHCertificate" has incompatible type "bytes | Any | memoryview[int]"; expected "bytes"  [arg-type]

dd-trace-py (https://github.com/DataDog/dd-trace-py)
- ddtrace/debugging/_function/discovery.py:215: error: Argument 2 to "undecorated" has incompatible type "str | Any | int | type[staticmethod[Any, Any]] | type[classmethod[Any, Any, Any]]"; expected "str"  [arg-type]

@hauntsaninja hauntsaninja merged commit 05742e2 into python:master Apr 29, 2026
24 checks passed
@hauntsaninja hauntsaninja deleted the narrowanyunion branch April 29, 2026 21:40
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.20 regression] Inconsistent narroving for unions involving Any

2 participants