mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 07:37:38 +00:00

## Summary As far as I can tell, the two existing tests did the exact same thing. Remove the redundant test, and add tests for all combinations of declared/not-declared and local/"public" use of the name. Proposing this as a separate PR before the behavior might change via https://github.com/astral-sh/ruff/pull/18750
930 B
930 B
Builtin scope
Conditional local override of builtin
If a builtin name is conditionally shadowed by a local variable, a name lookup should union the builtin type with the conditionally-defined type:
def _(flag: bool) -> None:
if flag:
abs = 1
chr: int = 1
reveal_type(abs) # revealed: Literal[1] | (def abs(x: SupportsAbs[_T], /) -> _T)
reveal_type(chr) # revealed: Literal[1] | (def chr(i: SupportsIndex, /) -> str)
Conditionally global override of builtin
If a builtin name is conditionally shadowed by a global variable, a name lookup should union the builtin type with the conditionally-defined type:
def flag() -> bool:
return True
if flag():
abs = 1
chr: int = 1
def _():
reveal_type(abs) # revealed: Unknown | Literal[1] | (def abs(x: SupportsAbs[_T], /) -> _T)
reveal_type(chr) # revealed: int | (def chr(i: SupportsIndex, /) -> str)