Commit 96fcd59
Re-widen custom properties after narrowing (#19296)
Fixes #10399
This is another smaller cleanup for
#7724. The current logic as
documented is IMO correct, for attributes (either properties or custom
descriptors) with setter type different from getter type, we narrow the
attribute type in an assignment if:
* The attribute is "normalizing", i.e. getter type is a subtype of
setter type (e.g. `Sequence[Employee]` is normalized to `tuple[Employee,
...]`)
* The given r.h.s. type in the assignment is a subtype of getter type
(and thus transitively the setter as well), e.g. `tuple[Manager, ...]`
vs `tuple[Employee, ...]` in the example above.
The problem was that this logic was implemented too literally, as a
result assignments that didn't satisfy these two rules were simply
ignored (thus making previous narrowing incorrectly "sticky"). In fact,
we also need to re-widen previously narrowed types whenever second
condition is not satisfied.
(I also decided to rename one variable name to make it more obvious.)
---------
Co-authored-by: Stanislav Terliakov <50529348+sterliakov@users.noreply.github.com>1 parent ad57093 commit 96fcd59
2 files changed
Lines changed: 27 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4594 | 4594 | | |
4595 | 4595 | | |
4596 | 4596 | | |
4597 | | - | |
| 4597 | + | |
4598 | 4598 | | |
4599 | 4599 | | |
4600 | 4600 | | |
| |||
4611 | 4611 | | |
4612 | 4612 | | |
4613 | 4613 | | |
4614 | | - | |
4615 | | - | |
| 4614 | + | |
| 4615 | + | |
4616 | 4616 | | |
4617 | 4617 | | |
4618 | 4618 | | |
4619 | 4619 | | |
4620 | 4620 | | |
4621 | 4621 | | |
4622 | | - | |
4623 | | - | |
| 4622 | + | |
| 4623 | + | |
4624 | 4624 | | |
4625 | 4625 | | |
4626 | | - | |
4627 | | - | |
4628 | | - | |
4629 | | - | |
4630 | | - | |
| 4626 | + | |
| 4627 | + | |
| 4628 | + | |
4631 | 4629 | | |
4632 | 4630 | | |
4633 | 4631 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2593 | 2593 | | |
2594 | 2594 | | |
2595 | 2595 | | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
0 commit comments