Skip to content

Conversation

@cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Dec 13, 2025

Followup to #20332 (comment)

Wrap the callable with ( ) if it's within a union to reduce ambiguity. This matches the pyright behavior.

def f1() -> int | None: return 1
def f2() -> int: return 1

reveal_type(f1)                     # def () -> builtins.int | None
reveal_type(f2 if int() else None)  # (def () -> builtins.int)) | None

@cdce8p cdce8p added the topic-pep-604 PEP 604 (union | operator) label Dec 13, 2025
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Nice, thank you!

@hauntsaninja hauntsaninja merged commit ab38885 into python:master Dec 13, 2025
23 checks passed
@cdce8p cdce8p deleted the union-syntax-wrap-callable branch December 13, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic-error-reporting How we report errors topic-pep-604 PEP 604 (union | operator)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants