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
Default values for generic attributes are unsafe #5703
A potential solution would be to disallow all default values for generic attributes except None. This is however a low priority, since it is a false negative, and a rare corner case.
We don’t need to go so far as disallowing all defaults other than None. Any default value is fine as long as the default value has a type that can be written without T. For example:
x: Sequence[T] = [] is fine because [] has type Sequence[Never], which can be written without T, but is convertible to Sequence[T] by covariance. That is, a single [] may simultaneously have type Sequence[T] for all T.
x: List[T] = [] must be disallowed; no single [] may simultaneously have type List[T] for all T.
Activity
andersk commentedon Jul 2, 2022
Same issue as #11538.
We don’t need to go so far as disallowing all defaults other than
None. Any default value is fine as long as the default value has a type that can be written withoutT. For example:x: Sequence[T] = []is fine because[]has typeSequence[Never], which can be written withoutT, but is convertible toSequence[T]by covariance. That is, a single[]may simultaneously have typeSequence[T]for allT.x: List[T] = []must be disallowed; no single[]may simultaneously have typeList[T]for allT.