Question
A real use case I have found is something similar to the following snippet, to not repeat the available options:
from typing import Literal, get_args
type Value = Literal['a', 'b']
VALUES = get_args(Value)
def foo(x: Value): pass
def bar(x: str):
if x in VALUES:
foo(x) # invalid-argument-type
Ty check fails because the type annotation of get_args is too general ((tp: Any) -> tuple[Any, ...]).
To support this pattern, could the get_args function be special cased to better infer the resulting type, at least when the type is a Literal?
Version
ty 0.0.31
Question
A real use case I have found is something similar to the following snippet, to not repeat the available options:
Ty check fails because the type annotation of
get_argsis too general ((tp: Any) -> tuple[Any, ...]).To support this pattern, could the
get_argsfunction be special cased to better infer the resulting type, at least when the type is aLiteral?Version
ty 0.0.31