mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:25:17 +00:00
[red-knot] Support typing.TYPE_CHECKING
(#14952)
## Summary Add support for `typing.TYPE_CHECKING` and `typing_extensions.TYPE_CHECKING`. relates to: https://github.com/astral-sh/ruff/issues/14170 ## Test Plan New Markdown-based tests
This commit is contained in:
parent
f52b1f4a4d
commit
e96b13c027
2 changed files with 60 additions and 0 deletions
|
@ -120,6 +120,14 @@ fn symbol_by_id<'db>(db: &'db dyn Db, scope: ScopeId<'db>, symbol: ScopedSymbolI
|
|||
|
||||
/// Shorthand for `symbol_by_id` that takes a symbol name instead of an ID.
|
||||
fn symbol<'db>(db: &'db dyn Db, scope: ScopeId<'db>, name: &str) -> Symbol<'db> {
|
||||
// We don't need to check for `typing_extensions` here, because `typing_extensions.TYPE_CHECKING`
|
||||
// is just a re-export of `typing.TYPE_CHECKING`.
|
||||
if name == "TYPE_CHECKING"
|
||||
&& file_to_module(db, scope.file(db)).is_some_and(|module| module.name() == "typing")
|
||||
{
|
||||
return Symbol::Type(Type::BooleanLiteral(true), Boundness::Bound);
|
||||
}
|
||||
|
||||
let table = symbol_table(db, scope);
|
||||
table
|
||||
.symbol_id_by_name(name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue