File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -42,10 +42,8 @@ being addressed.]
42
42
Introduction
43
43
============
44
44
45
- PEP-484 introduced the concept of a union type, written `Union[A, B] ` which describes values of
46
- either type `A ` or type `B `.
47
- Intersection types provide a different (complementary) way of combining types.
48
- The type `A & B ` describes values which have both type `A ` and type `B `.
45
+ PEP-484 introduced the concept of a union type, written ``Union[A, B] `` which describes values of
46
+ either type ``A `` or type ``B ``.
49
47
50
48
For example,
51
49
@@ -56,11 +54,30 @@ For example,
56
54
class C(A, B): ...
57
55
class D(A): ...
58
56
59
- def f(value: A & B): ...
57
+ # PEP-604 was introduced to allow writing `Union[X, Y]` as `X | Y`
58
+ def fu(value: A | B): ...
59
+
60
+ fu(A()) # Valid
61
+ fu(B()) # Valid
62
+ fu(C()) # Valid
63
+ fu(D()) # Valid
64
+
65
+ Intersection types provide a different (complementary) way of combining types.
66
+ The type ``A & B `` describes values which have both type ``A `` and type ``B ``.
67
+
68
+ For example,
69
+
70
+ ::
71
+
72
+ def fi(value: A & B): ...
60
73
74
+ fi(A()) # Invalid
75
+ fi(B()) # Invalid
76
+ fi(C()) # Valid
77
+ fi(D()) # Invalid
61
78
62
- here it is valid to call `f ` on an instance of `C ` , but invalid to call it with instances of ` A `,
63
- `B ` or `D `.
79
+ here it is valid to call `` fi `` on an instance of `` C `` , but invalid to call it with instances of
80
+ `` A ``, `` B `` or `` D ` `.
64
81
65
82
Motivation
66
83
==========
You can’t perform that action at this time.
0 commit comments