mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +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
|
@ -880,6 +880,30 @@ where
|
|||
|
||||
self.current_match_case.as_mut().unwrap().index += 1;
|
||||
}
|
||||
|
||||
fn visit_except_handler(&mut self, except_handler: &'ast ast::ExceptHandler) {
|
||||
let ast::ExceptHandler::ExceptHandler(except_handler) = except_handler;
|
||||
let ast::ExceptHandlerExceptHandler {
|
||||
name: symbol_name,
|
||||
type_: handled_exceptions,
|
||||
body,
|
||||
range: _,
|
||||
} = except_handler;
|
||||
|
||||
if let Some(handled_exceptions) = handled_exceptions {
|
||||
self.visit_expr(handled_exceptions);
|
||||
}
|
||||
|
||||
// If `handled_exceptions` above was `None`, it's something like `except as e:`,
|
||||
// which is invalid syntax. However, it's still pretty obvious here that the user
|
||||
// *wanted* `e` to be bound, so we should still create a definition here nonetheless.
|
||||
if let Some(symbol_name) = symbol_name {
|
||||
let symbol = self.add_or_update_symbol(symbol_name.id.clone(), SymbolFlags::IS_DEFINED);
|
||||
self.add_definition(symbol, except_handler);
|
||||
}
|
||||
|
||||
self.visit_body(body);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue