@@ -259,15 +259,15 @@ For class methods, you can also define generic ``cls``, using :py:class:`type`:
259259
260260.. code-block :: python
261261
262- from typing import TypeVar, Type
262+ from typing import Optional, TypeVar, Type
263263
264264 T = TypeVar(' T' , bound = ' Friend' )
265265
266266 class Friend :
267- other: " Friend" = None
267+ other: Optional[ " Friend" ] = None
268268
269269 @ classmethod
270- def make_pair (cls : Type [T]) -> tuple[T, T]:
270+ def make_pair (cls : type [T]) -> tuple[T, T]:
271271 a, b = cls (), cls ()
272272 a.other = b
273273 b.other = a
@@ -674,19 +674,19 @@ alter the signature of the input function:
674674 P = ParamSpec(' P' )
675675 T = TypeVar(' T' )
676676
677- # We reuse 'P' in the return type, but replace 'T' with 'str'
677+ # We reuse 'P' in the return type, but replace 'T' with 'str'
678678 def stringify (func : Callable[P, T]) -> Callable[P, str ]:
679679 def wrapper (* args : P.args, ** kwds : P.kwargs) -> str :
680680 return str (func(* args, ** kwds))
681681 return wrapper
682682
683- @stringify
684- def add_forty_two (value : int ) -> int :
685- return value + 42
683+ @stringify
684+ def add_forty_two (value : int ) -> int :
685+ return value + 42
686686
687- a = add_forty_two(3 )
688- reveal_type(a) # Revealed type is "builtins.str"
689- add_forty_two(' x' ) # error: Argument 1 to "add_forty_two" has incompatible type "str"; expected "int"
687+ a = add_forty_two(3 )
688+ reveal_type(a) # Revealed type is "builtins.str"
689+ add_forty_two(' x' ) # error: Argument 1 to "add_forty_two" has incompatible type "str"; expected "int"
690690
691691 Or insert an argument:
692692
0 commit comments