[ty] support accessing __builtins__ global (#18118)
## Summary The PR adds an explicit check for `"__builtins__"` during name lookup, similar to how `"__file__"` is implemented. The inferred type is `Any`. closes https://github.com/astral-sh/ty/issues/393 ## Test Plan Added a markdown test for `__builtins__`. --------- Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
This commit is contained in:
@@ -324,6 +324,8 @@ pub(crate) fn imported_symbol<'db>(
|
||||
|| {
|
||||
if name == "__getattr__" {
|
||||
Symbol::Unbound.into()
|
||||
} else if name == "__builtins__" {
|
||||
Symbol::bound(Type::any()).into()
|
||||
} else {
|
||||
KnownClass::ModuleType.to_instance(db).member(db, name)
|
||||
}
|
||||
@@ -1013,6 +1015,8 @@ mod implicit_globals {
|
||||
// None`.
|
||||
if name == "__file__" {
|
||||
Symbol::bound(KnownClass::Str.to_instance(db)).into()
|
||||
} else if name == "__builtins__" {
|
||||
Symbol::bound(Type::any()).into()
|
||||
}
|
||||
// In general we wouldn't check to see whether a symbol exists on a class before doing the
|
||||
// `.member()` call on the instance type -- we'd just do the `.member`() call on the instance
|
||||
|
||||
Reference in New Issue
Block a user