mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
[red-knot] Support re-export conventions for stub files (#16073)
This is an alternative implementation to #15848. ## Summary This PR adds support for re-export conventions for imports for stub files. **How does this work?** * Add a new flag on the `Import` and `ImportFrom` definitions to indicate whether they're being exported or not * Add a new enum to indicate whether the symbol lookup is happening within the same file or is being queried from another file (e.g., an import statement) * When a `Symbol` is being queried, we'll skip the definitions that are (a) coming from a stub file (b) external lookup and (c) check the re-export flag on the definition This implementation does not yet support `__all__` and `*` imports as both are features that needs to be implemented independently. closes: #14099 closes: #15476 ## Test Plan Add test cases, update existing ones if required.
This commit is contained in:
parent
3d0a58eb60
commit
60b3ef2c98
7 changed files with 594 additions and 101 deletions
|
@ -2,7 +2,7 @@ use crate::module_resolver::{resolve_module, KnownModule};
|
|||
use crate::semantic_index::global_scope;
|
||||
use crate::semantic_index::symbol::ScopeId;
|
||||
use crate::symbol::Symbol;
|
||||
use crate::types::global_symbol;
|
||||
use crate::types::{global_symbol, SymbolLookup};
|
||||
use crate::Db;
|
||||
|
||||
/// Lookup the type of `symbol` in a given known module
|
||||
|
@ -14,7 +14,7 @@ pub(crate) fn known_module_symbol<'db>(
|
|||
symbol: &str,
|
||||
) -> Symbol<'db> {
|
||||
resolve_module(db, &known_module.name())
|
||||
.map(|module| global_symbol(db, module.file(), symbol))
|
||||
.map(|module| global_symbol(db, SymbolLookup::External, module.file(), symbol))
|
||||
.unwrap_or(Symbol::Unbound)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue