← Back to index
generics_syntax_compatibility.py
True Positive
False Positive
False Negative
Optional (detected)
Warning or Info
TP: 0
FP: 0
FN: 2
Optional: 0 / 0
1
"""
2
Tests
the
compatibility
rules
between
type
parameter
syntax
(
introduced
in
PEP
695
)
3
and
traditional
TypeVars
.
4
"""
5
6
# Specification: https://peps.python.org/pep-0695/#compatibility-with-traditional-typevars
7
8
from
typing
import
TypeVar
9
10
11
K
=
TypeVar
(
"K"
)
12
13
14
class
ClassA
[
V
](
dict
[
K
,
V
]):
# E: traditional TypeVar not allowed here
Expected a ty diagnostic for this line
15
...
16
17
18
class
ClassB
[
K
,
V
](
dict
[
K
,
V
]):
# OK
19
...
20
21
22
class
ClassC
[
V
]:
23
def
method1
(
self
,
a
:
V
,
b
:
K
)
->
V
|
K
:
# OK
24
raise
NotImplementedError
25
26
def
method2
[
M
](
self
,
a
:
M
,
b
:
K
)
->
M
|
K
:
# E
Expected a ty diagnostic for this line
27
raise
NotImplementedError