Skip to content

Commit

Permalink
[red-knot] Add type inference for loop variables inside comprehension…
Browse files Browse the repository at this point in the history
… scopes (#13251)
  • Loading branch information
AlexWaygood committed Sep 9, 2024
1 parent ac720cd commit 6f53aaf
Show file tree
Hide file tree
Showing 3 changed files with 370 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ where
iterable: &node.iter,
target: name_node,
first,
is_async: node.is_async,
},
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ pub(crate) struct ComprehensionDefinitionNodeRef<'a> {
pub(crate) iterable: &'a ast::Expr,
pub(crate) target: &'a ast::ExprName,
pub(crate) first: bool,
pub(crate) is_async: bool,
}

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -227,10 +228,12 @@ impl DefinitionNodeRef<'_> {
iterable,
target,
first,
is_async,
}) => DefinitionKind::Comprehension(ComprehensionDefinitionKind {
iterable: AstNodeRef::new(parsed.clone(), iterable),
target: AstNodeRef::new(parsed, target),
first,
is_async,
}),
DefinitionNodeRef::Parameter(parameter) => match parameter {
ast::AnyParameterRef::Variadic(parameter) => {
Expand Down Expand Up @@ -337,6 +340,7 @@ pub struct ComprehensionDefinitionKind {
iterable: AstNodeRef<ast::Expr>,
target: AstNodeRef<ast::ExprName>,
first: bool,
is_async: bool,
}

impl ComprehensionDefinitionKind {
Expand All @@ -351,6 +355,10 @@ impl ComprehensionDefinitionKind {
pub(crate) fn is_first(&self) -> bool {
self.first
}

pub(crate) fn is_async(&self) -> bool {
self.is_async
}
}

#[derive(Clone, Debug)]
Expand Down
Loading

0 comments on commit 6f53aaf

Please sign in to comment.