Skip to content

Commit 2ef3bdc

Browse files
author
Guido van Rossum
committed
Add proposed resolution to most open issues.
1 parent 8c4ac6c commit 2ef3bdc

File tree

1 file changed

+38
-16
lines changed

1 file changed

+38
-16
lines changed

README.rst

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,58 +26,72 @@ Work in progress notes
2626
precedent in ``abc``, namely ``Callable``, and ``Hashable``.
2727
However, attempts at implementing reasonable runtime behavior
2828
suggests that it may be better to leave ``collections.abc`` alone.
29+
**Proposed resolution: leave ``collections.abc`` alone.**
2930

3031
* ``Var('T')`` is put in ``collections.abc`` as a helper with generics
3132
and covariance/contravariance in ABCs. May be renamed to ``TypeVar``.
3233
The co-/contravariance behavior requires more thinking.
34+
**Proposed resolution: Use ``TypeVar``, with mypy's semantics mapped:
35+
``typevar('T', values=(str, bytes)`` becomes ``TypeVar('T', str, bytes)``.**
3336

3437
* ``AnyStr`` (and consequently ``IO``) smells like basestring in
3538
disguise, what is the use case for Python 3? Answer: There are
3639
lots of things in the stdlib that are essentially overloaded as
3740
str-in-str-out and bytes-in-bytes-out; ``AnyStr`` has exactly the
3841
right behavior for this (unlike ``Union[str, bytes]``).
42+
**Proposed resolution: keep ``AnyStr``, ``IO`` and its subclasses,
43+
in typing.py.**
3944

40-
* ``Undefined`` smells like JavaScript, I left it out for now.
45+
* ``Undefined`` smells like JavaScript, I (Łukasz) left it out for now.
4146
However, mypy needs it. See https://github.com/ambv/typehinting/issues/20
47+
**Help???**
4248

4349
* The addition of ``Match`` and ``Pattern`` seems arbitrary and should
4450
rather be fixed in ``re`` directly, with the types just imported in
4551
``typing``. If so, are there any other potentially useful types we'd
4652
like? See https://github.com/ambv/typehinting/issues/23
53+
**Proposed resolution: keep these two in typing.py for convenience.**
4754

48-
* I left out ``overload`` because I don't understand its purpose. If we
55+
* I (Łukasz) left out ``overload`` because I don't understand its purpose. If we
4956
need generic dispatch, we should add it to ``functools``.
5057
Perhaps ``overload`` should only be allowed in stub modules?
5158
See https://github.com/ambv/typehinting/issues/14
59+
**Proposed resolution: support the syntax but only in stub files.**
5260

53-
* I left out specifying protocols as they are an ABC implementation
61+
* I (Łukasz) left out specifying protocols as they are an ABC implementation
5462
detail from the perspective of this PEP. However, they should be
5563
defined in a separate PEP because making ``__subclasshook__`` less
5664
dynamic when possible (which is often) would make ABCs much better
5765
behaved in static analysis contexts.
5866
See https://github.com/ambv/typehinting/issues/11
67+
**Help???**
5968

6069
* Having the last thing in mind, ``IO``, ``BinaryIO`` and ``TextIO``
6170
would simply be new abstract base classes, usable with or without type
62-
hinting
71+
hinting.
72+
**Proposed resolution: ``IO`` is generic over ``AnyStr``, the other two
73+
are concrete (subclassing ``IO[bytes]`` and ``IO[str]`` respectively).**
6374

64-
* the current implementation of ``*IO`` is quite un-ducktyped (specifies
75+
* The current implementation of ``*IO`` is quite un-ducktyped (specifies
6576
both reading and writing as one protocol)
77+
**Help???**
6678

67-
* I left out ``cast`` because it can be more consistently expressed as::
79+
* I (Łukasz) left out ``cast`` because it can be more consistently expressed as::
6880

6981
bad_typed_list = [1, 2, 3] # type: list
7082
...
7183
well_typed_list = bad_typed_list # type: List[int]
7284

7385
See https://github.com/ambv/typehinting/issues/15
86+
**Proposed resolution: add ``cast(type, value)`` back in.**
7487

75-
* I removed ``mypy`` from the listed "existing approaches" since we
76-
basically describe what mypy is
88+
* I (Łukasz) removed ``mypy`` from the listed "existing approaches" since we
89+
basically describe what mypy is. **Proposed resolution: fine.**
7790

78-
* I thought if introducing optional contravariance/invariance to ``Var``
91+
* I (Łukasz) thought if introducing optional contravariance/invariance to ``Var``
7992
has merit but I'm undecided; definitely complicates the type checker.
8093
See https://github.com/ambv/typehinting/issues/2
94+
**Help???**
8195

8296

8397
Changes to MyPy coming from this proposal
@@ -90,10 +104,12 @@ Changes to MyPy coming from this proposal
90104
https://github.com/JukkaL/mypy/issues/539 and
91105
https://github.com/ambv/typehinting/issues/1 and
92106
https://github.com/ambv/typehinting/issues/2 and maybe others.
93-
107+
**Proposed resolution: ``TypeVar`` (see above).**
94108

95109
* ``Union`` behaves differently, it holds the defined types in order
96110
to be able to actually respond to issubclass.
111+
**Proposed resolution: This doesn't affect mypy; I do want this for
112+
typing.py (also for generic types).**
97113

98114
* ``typing.Function`` becomes ``typing.Callable``, which is equivalent
99115
to ``collections.abc.Callable``. (Has now been implemented in mypy.)
@@ -108,23 +124,29 @@ Open issues
108124
* State of the art: should we list decorator-based approaches
109125
(PyContracts?) and docstring-based approaches?
110126

111-
* should we recommend the use of ABCs over builtin types when possible?
127+
* Should we recommend the use of ABCs over builtin types when possible?
112128

113-
* should we provide type shortcuts so that MutableMapping is not 3.5x
129+
* Should we provide type shortcuts so that MutableMapping is not 3.5x
114130
longer to type than dict?
115131

116-
* is multiple dispatch using type hints in scope for this PEP?
132+
* Is multiple dispatch using type hints in scope for this PEP?
133+
**Proposed resolution: let's wait, allow @overload only in stubs.**
117134

118-
* should we mention platform- or version-specific typing? Guido mentioned
135+
* Should we mention platform- or version-specific typing? Guido mentioned
119136
Windows vs. POSIX during the Skype meeting.
137+
**Proposed resolution: let typing.py export a few specific constants;
138+
PY3, PY2, PY3_x (for x in 2, 3, 4, 5).**
120139

121-
* it would be useful to have a ``Subclass[]`` factory that would be
140+
* It would be useful to have a ``Subclass[]`` factory that would be
122141
equivalent to "any class that has the all the following classes in its
123142
MRO". Maybe we'd want to rename union to ``Any[]`` and this new
124143
proposed type to ``All[]``? See https://github.com/ambv/typehinting/issues/18
144+
**Proposed resolution: let's just have ``Union[T1, T2, ...]`` and ``Any``.**
125145

126146
* Callable signature definition should be explained and support all
127-
valid function signatures
147+
valid function signatures.
148+
**Proposed resolution: ``Callable[[T1, T2, ...], Tr]``.**
128149

129150
* What about all other collections available in the ``collections``
130151
module?
152+
**Proposed resolution: make Generic types retain their argument type(s).**

0 commit comments

Comments
 (0)