@@ -22,30 +22,40 @@ Work in progress notes
22
22
23
23
* Putting new things in ``collections.abc `` seems fine as long as those
24
24
new elements are actual abstract base classes that are collections.
25
- I lessened this latter requirement since there's non-collection
25
+ I (Łukasz) lessened this latter requirement since there's non-collection
26
26
precedent in ``abc ``, namely ``Callable ``, and ``Hashable ``.
27
+ However, attempts at implementing reasonable runtime behavior
28
+ suggests that it may be better to leave ``collections.abc `` alone.
27
29
28
30
* ``Var('T') `` is put in ``collections.abc `` as a helper with generics
29
- and covariance/contravariance in ABCs
31
+ and covariance/contravariance in ABCs. May be renamed to ``TypeVar ``.
32
+ The co-/contravariance behavior requires more thinking.
30
33
31
34
* ``AnyStr `` (and consequently ``IO ``) smells like basestring in
32
- disguise, what is the use case for Python 3?
35
+ disguise, what is the use case for Python 3? Answer: There are
36
+ lots of things in the stdlib that are essentially overloaded as
37
+ str-in-str-out and bytes-in-bytes-out; ``AnyStr `` has exactly the
38
+ right behavior for this (unlike ``Union[str, bytes] ``).
33
39
34
- * ``Undefined `` smells like JavaScript, I left it out for now
40
+ * ``Undefined `` smells like JavaScript, I left it out for now.
41
+ However, mypy needs it. See https://github.com/ambv/typehinting/issues/20
35
42
36
43
* The addition of ``Match `` and ``Pattern `` seems arbitrary and should
37
44
rather be fixed in ``re `` directly, with the types just imported in
38
45
``typing ``. If so, are there any other potentially useful types we'd
39
- like?
46
+ like? See https://github.com/ambv/typehinting/issues/23
40
47
41
48
* I left out ``overload `` because I don't understand its purpose. If we
42
- need generic dispatch, we should add it to ``functools ``
49
+ need generic dispatch, we should add it to ``functools ``.
50
+ Perhaps ``overload `` should only be allowed in stub modules?
51
+ See https://github.com/ambv/typehinting/issues/14
43
52
44
53
* I left out specifying protocols as they are an ABC implementation
45
54
detail from the perspective of this PEP. However, they should be
46
55
defined in a separate PEP because making ``__subclasshook__ `` less
47
56
dynamic when possible (which is often) would make ABCs much better
48
- behaved in static analysis contexts
57
+ behaved in static analysis contexts.
58
+ See https://github.com/ambv/typehinting/issues/11
49
59
50
60
* Having the last thing in mind, ``IO ``, ``BinaryIO `` and ``TextIO ``
51
61
would simply be new abstract base classes, usable with or without type
@@ -60,11 +70,14 @@ Work in progress notes
60
70
...
61
71
well_typed_list = bad_typed_list # type: List[int]
62
72
73
+ See https://github.com/ambv/typehinting/issues/15
74
+
63
75
* I removed ``mypy `` from the listed "existing approaches" since we
64
- basically describe what MyPy is
76
+ basically describe what mypy is
65
77
66
78
* I thought if introducing optional contravariance/invariance to ``Var ``
67
- has merit but I'm undecided; definitely complicates the type checker
79
+ has merit but I'm undecided; definitely complicates the type checker.
80
+ See https://github.com/ambv/typehinting/issues/2
68
81
69
82
70
83
Changes to MyPy coming from this proposal
@@ -73,21 +86,23 @@ Changes to MyPy coming from this proposal
73
86
* ``typevar `` becomes ``Var('T') `` and its semantics support specifying
74
87
base type constraints. If we decide to add optional invariance or
75
88
contravariance, this will be the place, too.
89
+ Or perhaps ``TypeVar('T') ``. See
90
+ https://github.com/JukkaL/mypy/issues/539 and
91
+ https://github.com/ambv/typehinting/issues/1 and
92
+ https://github.com/ambv/typehinting/issues/2 and maybe others.
93
+
76
94
77
- * ``collections.abc.Union `` behaves differently, it holds the defined
78
- types to be able to actually respond to issubclass. Consequently,
79
- ``typing.AnyStr `` becomes an ``Union `` instead of ``typevar('AnyStr',
80
- values=(str, bytes)) `` (which is consciously impossible to express in
81
- the ``Var `` notation, unless you're using a Union as ``base= ``)
95
+ * ``Union `` behaves differently, it holds the defined types in order
96
+ to be able to actually respond to issubclass.
82
97
83
98
* ``typing.Function `` becomes ``typing.Callable ``, which is equivalent
84
- to ``collections.abc.Callable ``
99
+ to ``collections.abc.Callable ``. (Has now been implemented in mypy.)
85
100
86
101
87
102
Open issues
88
103
-----------
89
104
90
- * How to make the union type land in __annotations__ for the ``x:str
105
+ * How to make the union type land in __annotations__ for the ``x: str
91
106
= None `` case?
92
107
93
108
* State of the art: should we list decorator-based approaches
@@ -100,13 +115,13 @@ Open issues
100
115
101
116
* is multiple dispatch using type hints in scope for this PEP?
102
117
103
- * should we mention platform- or Python -specific typing? Guido mentioned
118
+ * should we mention platform- or version -specific typing? Guido mentioned
104
119
Windows vs. POSIX during the Skype meeting.
105
120
106
121
* it would be useful to have a ``Subclass[] `` factory that would be
107
122
equivalent to "any class that has the all the following classes in its
108
123
MRO". Maybe we'd want to rename union to ``Any[] `` and this new
109
- proposed type to ``All[] ``?
124
+ proposed type to ``All[] ``? See https://github.com/ambv/typehinting/issues/18
110
125
111
126
* Callable signature definition should be explained and support all
112
127
valid function signatures
0 commit comments