Skip to content

Commit 161446a

Browse files
[ty] Add support for global __debug__ constant (#18540)
## Summary Closes astral-sh/ty#577. Make global `__debug__` a `bool` constant. ## Test Plan Mdtest `global-constants.md` was created to check if resolved type was `bool`. --------- Co-authored-by: David Peter <mail@david-peter.de>
1 parent caf885c commit 161446a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Global Constants
2+
3+
## `__debug__` constant
4+
5+
The [`__debug__` constant] should be globally available:
6+
7+
```py
8+
reveal_type(__debug__) # revealed: bool
9+
10+
def foo():
11+
reveal_type(__debug__) # revealed: bool
12+
```
13+
14+
[`__debug__` constant]: https://docs.python.org/3/library/constants.html#debug__

crates/ty_python_semantic/src/place.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,8 @@ mod implicit_globals {
10731073
Place::bound(KnownClass::Str.to_instance(db)).into()
10741074
} else if name == "__builtins__" {
10751075
Place::bound(Type::any()).into()
1076+
} else if name == "__debug__" {
1077+
Place::bound(KnownClass::Bool.to_instance(db)).into()
10761078
}
10771079
// In general we wouldn't check to see whether a symbol exists on a class before doing the
10781080
// `.member()` call on the instance type -- we'd just do the `.member`() call on the instance

0 commit comments

Comments
 (0)