@@ -259,15 +259,15 @@ For class methods, you can also define generic ``cls``, using :py:class:`type`:
259
259
260
260
.. code-block :: python
261
261
262
- from typing import TypeVar, Type
262
+ from typing import Optional, TypeVar, Type
263
263
264
264
T = TypeVar(' T' , bound = ' Friend' )
265
265
266
266
class Friend :
267
- other: " Friend" = None
267
+ other: Optional[ " Friend" ] = None
268
268
269
269
@ classmethod
270
- def make_pair (cls : Type [T]) -> tuple[T, T]:
270
+ def make_pair (cls : type [T]) -> tuple[T, T]:
271
271
a, b = cls (), cls ()
272
272
a.other = b
273
273
b.other = a
@@ -674,19 +674,19 @@ alter the signature of the input function:
674
674
P = ParamSpec(' P' )
675
675
T = TypeVar(' T' )
676
676
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'
678
678
def stringify (func : Callable[P, T]) -> Callable[P, str ]:
679
679
def wrapper (* args : P.args, ** kwds : P.kwargs) -> str :
680
680
return str (func(* args, ** kwds))
681
681
return wrapper
682
682
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
686
686
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"
690
690
691
691
Or insert an argument:
692
692
0 commit comments