Skip to content

Commit

Permalink
[red-knot] Add a regression test for recent improvement to `TypeInfer…
Browse files Browse the repository at this point in the history
…enceBuilder::infer_name_load()` (#16310)
  • Loading branch information
AlexWaygood authored Feb 21, 2025
1 parent 224a36f commit 64effa4
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,42 @@ if returns_bool():
reveal_type(__file__) # revealed: Literal[42]
reveal_type(__name__) # revealed: Literal[1] | str
```

## Implicit global attributes in the current module override implicit globals from builtins

Here, we take the type of the implicit global symbol `__name__` from the `types.ModuleType` stub
(which in this custom typeshed specifies the type as `bytes`). This is because the `main` module has
an implicit `__name__` global that shadows the builtin `__name__` symbol.

```toml
[environment]
typeshed = "/typeshed"
```

`/typeshed/stdlib/builtins.pyi`:

```pyi
class int: ...
class bytes: ...

__name__: int = 42
```

`/typeshed/stdlib/types.pyi`:

```pyi
class ModuleType:
__name__: bytes
```

`/typeshed/stdlib/typing_extensions.pyi`:

```pyi
def reveal_type(obj, /): ...
```

`main.py`:

```py
reveal_type(__name__) # revealed: bytes
```

0 comments on commit 64effa4

Please sign in to comment.