We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 646427f commit 434f8d2Copy full SHA for 434f8d2
08-def-type-hints/callable/variance.py
@@ -0,0 +1,22 @@
1
+from collections.abc import Callable
2
+
3
+def update( # <1>
4
+ probe: Callable[[], float], # <2>
5
+ display: Callable[[float], None] # <3>
6
+ ) -> None:
7
+ temperature = probe()
8
+ # imagine lots of control code here
9
+ display(temperature)
10
11
+def probe_ok() -> int: # <4>
12
+ return 42
13
14
+def display_wrong(temperature: int) -> None: # <5>
15
+ print(hex(temperature))
16
17
+update(probe_ok, display_wrong) # type error # <6>
18
19
+def display_ok(temperature: complex) -> None: # <7>
20
+ print(temperature)
21
22
+update(probe_ok, display_ok) # OK # <8>
0 commit comments