Bug Report
Self is only valid in the specific locations listed in PEP 673 and Mypy already rejects several invalid locations.
See:
|
[case testTypingSelfInvalidLocations] |
It seems one location wasn't covered: using Self as the bound (or constraint) of a PEP 695 type parameter.
To Reproduce:
from typing import Self
class Foo:
def fails[T: Self](self: T) -> None: pass
Expected Behavior
Mypy should reject Self here with an error.
From a quick look at other type checkers: pyright and ty treat it as an invalid/generic TypeVar bound (TypeVar upper bound cannot be generic), while zuban rejects it with the same message mypy already uses elsewhere,
Self type is only allowed in annotations within class definition.
Actual Behavior
No error is reported.
Your Environment
Mypy version: ae39cdb
Python version: 3.12
TLDR; originally spotted while working on #21928 See: #21928 (comment)
Bug Report
Self is only valid in the specific locations listed in PEP 673 and Mypy already rejects several invalid locations.
See:
mypy/test-data/unit/check-selftype.test
Line 1480 in ae39cdb
It seems one location wasn't covered: using Self as the bound (or constraint) of a PEP 695 type parameter.
To Reproduce:
Expected Behavior
Mypy should reject
Selfhere with an error.From a quick look at other type checkers: pyright and ty treat it as an invalid/generic TypeVar bound (
TypeVar upper bound cannot be generic), while zuban rejects it with the same message mypy already uses elsewhere,Self type is only allowed in annotations within class definition.Actual Behavior
No error is reported.
Your Environment
Mypy version: ae39cdb
Python version: 3.12
TLDR; originally spotted while working on #21928 See: #21928 (comment)