Skip to content

[ty] Minor change to builtins.md test #18889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions crates/ty_python_semantic/resources/mdtest/scopes/builtin.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
# Builtin scope

## Conditionally global or builtin
## Conditional local override of builtin

If a builtin name is conditionally defined as a global, a name lookup should union the builtin type
with the conditionally-defined type:
If a builtin name is conditionally shadowed by a local variable, a name lookup should union the
builtin type with the conditionally-defined type:

```py
def returns_bool() -> bool:
return True

if returns_bool():
chr: int = 1
def _(flag: bool) -> None:
if flag:
abs = 1
chr: int = 1

def f():
reveal_type(chr) # revealed: int | (def chr(i: SupportsIndex, /) -> str)
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 or builtin, with annotation
## Conditionally global override of builtin

Same is true if the name is annotated:
If a builtin name is conditionally shadowed by a global variable, a name lookup should union the
builtin type with the conditionally-defined type:

```py
def returns_bool() -> bool:
def flag() -> bool:
return True

if returns_bool():
if flag():
abs = 1
chr: int = 1

def f():
def _():
reveal_type(abs) # revealed: Unknown | Literal[1] | (def abs(x: SupportsAbs[_T], /) -> _T)
reveal_type(chr) # revealed: int | (def chr(i: SupportsIndex, /) -> str)
```