[red-knot] Add notebook support (#12338)

This commit is contained in:
Micha Reiser 2024-07-17 10:26:33 +02:00 committed by GitHub
parent fe04f2b09d
commit 0c72577b5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 246 additions and 53 deletions

View file

@ -86,12 +86,19 @@ impl PySourceType {
///
/// Falls back to `Python` if the extension is not recognized.
pub fn from_extension(extension: &str) -> Self {
match extension {
Self::try_from_extension(extension).unwrap_or_default()
}
/// Infers the source type from the file extension.
pub fn try_from_extension(extension: &str) -> Option<Self> {
let ty = match extension {
"py" => Self::Python,
"pyi" => Self::Stub,
"ipynb" => Self::Ipynb,
_ => Self::Python,
}
_ => return None,
};
Some(ty)
}
}