Skip to content

Tuple elements remain optional after an any() None check #5434

Closed

Description

@rockstaryy

Describe the Bug

After checking that no tuple element is None, Pyrefly still treats the tuple elements as optional:

def pair(
    first: int | None,
    second: str | None,
) -> tuple[int, str]:
    values = (first, second)
    if any(value is None for value in values):
        raise ValueError("missing value")

    return values

I expected Pyrefly to infer values as tuple[int, str] after the guard. Instead, it reports:

Returned type `tuple[int | None, str | None]` is not assignable to declared return type `tuple[int, str]` [bad-return]

Environment: macOS 27.0.1, Pyrefly 1.4.0, Python 3.15.2 (CLI).

Activity

  1. added
    narrowingIssues with narrowing - root cause is usually narrowing, flow handling, or both
    on Oct 29, 2026
  2. 1-DARK commented on Nov 2, 2026

    @1-DARK
    Contributor

    #claim

  3. github-actions commented on Nov 2, 2026

    @github-actions

    @1-DARK you've claimed this issue — it's now assigned to you. Thanks for picking it up! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

has-open-prnarrowingIssues with narrowing - root cause is usually narrowing, flow handling, or both

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions