[red-knot] infer attribute assignments bound in comprehensions (#17396)

## Summary

This PR is a follow-up to #16852.

Instance variables bound in comprehensions are recorded, allowing type
inference to work correctly.

This required adding support for unpacking in comprehension which
resolves https://github.com/astral-sh/ruff/issues/15369.

## Test Plan

One TODO in `mdtest/attributes.md` is now resolved, and some new test
cases are added.

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
Shunsuke Shibayama 2025-04-19 10:12:48 +09:00 committed by GitHub
parent 2a478ce1b2
commit da6b68cb58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 349 additions and 108 deletions

View file

@ -940,7 +940,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs):
panic!("expected generator definition")
};
let target = comprehension.target();
let name = target.id().as_str();
let name = target.as_name_expr().unwrap().id().as_str();
assert_eq!(name, "x");
assert_eq!(target.range(), TextRange::new(23.into(), 24.into()));