You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
0 commit comments