Skip to content

Conditional expression with branches of type None and T should be Optional[T], not object #1820

Closed
@gvanrossum

Description

@gvanrossum

Consider:

def f(flag; bool) -> Optional[int]:
  a = (None if flag else 0)
  return a

When run with --strict-optional I get the error

error: Incompatible return value type (got "object", expected "Optional[int]")

It looks like the unification code is not understanding what's going on and falling back on object.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions