Commit fe2e1f5
committed
Reject Self in PEP 695 type parameter bounds (#21960)
PEP 673 lists the valid locations for Self, and a PEP 695 type
parameter bound is not one of them. mypy accepted it silently:
class C:
def bounded[T: Self](self: T) -> None: ...
reported no error at all. Analysing the bound with
prohibit_self_type gives the same message mypy already uses for the
other invalid locations.
The constraint case is also covered. mypy already rejected it, but
as "TypeVar constraint type cannot be parametrized by type
variables", which names the wrong reason.1 parent ae39cdb commit fe2e1f5
2 files changed
Lines changed: 18 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1888 | 1888 | | |
1889 | 1889 | | |
1890 | 1890 | | |
1891 | | - | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
1892 | 1896 | | |
1893 | 1897 | | |
1894 | 1898 | | |
| |||
1929 | 1933 | | |
1930 | 1934 | | |
1931 | 1935 | | |
1932 | | - | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
1933 | 1941 | | |
1934 | 1942 | | |
1935 | 1943 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1446 | 1446 | | |
1447 | 1447 | | |
1448 | 1448 | | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
1449 | 1457 | | |
1450 | 1458 | | |
1451 | 1459 | | |
| |||
0 commit comments