mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
[red-knot] support deferred evaluation of type expressions (#13131)
Prototype deferred evaluation of type expressions by deferring evaluation of class bases in a stub file. This allows self-referential class definitions, as occur with the definition of `str` in typeshed (which inherits `Sequence[str]`). --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
c6023c03a2
commit
770ef2ab27
3 changed files with 207 additions and 40 deletions
|
@ -8,6 +8,7 @@ use salsa::{Durability, Setter};
|
|||
pub use file_root::{FileRoot, FileRootKind};
|
||||
pub use path::FilePath;
|
||||
use ruff_notebook::{Notebook, NotebookError};
|
||||
use ruff_python_ast::PySourceType;
|
||||
|
||||
use crate::file_revision::FileRevision;
|
||||
use crate::files::file_root::FileRoots;
|
||||
|
@ -424,6 +425,13 @@ impl File {
|
|||
pub fn exists(self, db: &dyn Db) -> bool {
|
||||
self.status(db) == FileStatus::Exists
|
||||
}
|
||||
|
||||
/// Returns `true` if the file should be analyzed as a type stub.
|
||||
pub fn is_stub(self, db: &dyn Db) -> bool {
|
||||
self.path(db)
|
||||
.extension()
|
||||
.is_some_and(|extension| PySourceType::from_extension(extension).is_stub())
|
||||
}
|
||||
}
|
||||
|
||||
/// A virtual file that doesn't exist on the file system.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue