79670382

Date: 2025-06-18 09:48:02
Score: 0.5
Natty:
Report link

Assign it to a variable and return it once.

from typing import Literal, assert_never, reveal_type

def foo(x: Literal["a", "b"]):
    match x:
        case "a":
            result = 42
        case "b":
            result = "string"
        case _:
            assert_never(x)
    return result

reveal_type(foo)  # Pyright infers: (x: Literal['a', 'b']) -> Literal[42, 'string']
Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Danilo Horta