mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-13 01:08:24 +00:00
[red-knot] Add definitions and limited type inference for exception handlers (#13267)
This commit is contained in:
parent
346dbf45b5
commit
1eb3e4057f
4 changed files with 190 additions and 3 deletions
|
|
@ -50,6 +50,7 @@ pub(crate) enum DefinitionNodeRef<'a> {
|
|||
Parameter(ast::AnyParameterRef<'a>),
|
||||
WithItem(WithItemDefinitionNodeRef<'a>),
|
||||
MatchPattern(MatchPatternDefinitionNodeRef<'a>),
|
||||
ExceptHandler(&'a ast::ExceptHandlerExceptHandler),
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::StmtFunctionDef> for DefinitionNodeRef<'a> {
|
||||
|
|
@ -130,6 +131,12 @@ impl<'a> From<MatchPatternDefinitionNodeRef<'a>> for DefinitionNodeRef<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::ExceptHandlerExceptHandler> for DefinitionNodeRef<'a> {
|
||||
fn from(node: &'a ast::ExceptHandlerExceptHandler) -> Self {
|
||||
Self::ExceptHandler(node)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub(crate) struct ImportFromDefinitionNodeRef<'a> {
|
||||
pub(crate) node: &'a ast::StmtImportFrom,
|
||||
|
|
@ -248,6 +255,9 @@ impl DefinitionNodeRef<'_> {
|
|||
identifier: AstNodeRef::new(parsed, identifier),
|
||||
index,
|
||||
}),
|
||||
DefinitionNodeRef::ExceptHandler(handler) => {
|
||||
DefinitionKind::ExceptHandler(AstNodeRef::new(parsed, handler))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -280,6 +290,7 @@ impl DefinitionNodeRef<'_> {
|
|||
Self::MatchPattern(MatchPatternDefinitionNodeRef { identifier, .. }) => {
|
||||
identifier.into()
|
||||
}
|
||||
Self::ExceptHandler(handler) => handler.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -300,6 +311,7 @@ pub enum DefinitionKind {
|
|||
ParameterWithDefault(AstNodeRef<ast::ParameterWithDefault>),
|
||||
WithItem(WithItemDefinitionKind),
|
||||
MatchPattern(MatchPatternDefinitionKind),
|
||||
ExceptHandler(AstNodeRef<ast::ExceptHandlerExceptHandler>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
@ -478,3 +490,9 @@ impl From<&ast::Identifier> for DefinitionNodeKey {
|
|||
Self(NodeKey::from_node(identifier))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&ast::ExceptHandlerExceptHandler> for DefinitionNodeKey {
|
||||
fn from(handler: &ast::ExceptHandlerExceptHandler) -> Self {
|
||||
Self(NodeKey::from_node(handler))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue