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
{{ message }}
Repository navigation
Type-narrowing from parent to child class produces Never if inheriting from a concrete version of a generic parent class. #16494
If I have a generic parent class, and I have a child class inheriting from a concrete version of the parent class, then I cannot type-narrow from the generic parent class to the child class. Trying to do the narrowing unexpectedly produces Never.
In my original code (not included here), this type-narrowing is after business logic that ensures that the object is an instance of the child class, and therefore the generic type is of the correct type. Additionally, this narrowing was done on self in a method in the parent class, so using Parent[Any] or Parent[int] isn't an option, since that requires changing the type of self.
changed the title [-]Can't type-narrow from parent to child class if inheriting from a concrete version of a generic parent class.[/-][+]Type-narrowing from parent to child class produces `Never` if inheriting from a concrete version of a generic parent class.[/+]on Nov 15, 2023
Activity
[-]Can't type-narrow from parent to child class if inheriting from a concrete version of a generic parent class.[/-][+]Type-narrowing from parent to child class produces `Never` if inheriting from a concrete version of a generic parent class.[/+]KotlinIsland commentedon Nov 30, 2023
When the concrete parameter is
None, an error message is shown and becomes unreachable.Do not narrow types to Never with binder (python#18972)
Do not narrow types to Never with binder (#18972)