You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec-draft.rst
+11-22Lines changed: 11 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,5 @@
1
-
===================================
2
1
Unpack of typevars for ``**kwargs``
3
-
===================================
2
+
-----------------------------------
4
3
5
4
A minor proposal that could be split out maybe:
6
5
@@ -20,9 +19,8 @@ This is basically a combination of "PEP 692 – Using TypedDict for more precise
20
19
21
20
This is potentially moderately useful on its own but is being done to support processing **kwargs with type level computation.
22
21
23
-
==========================
24
22
Extended Callables, take 2
25
-
==========================
23
+
--------------------------
26
24
27
25
We introduce a ``Param`` type the contains all the information about a function param::
28
26
@@ -61,9 +59,8 @@ as (we are omiting the ``Literal`` in places)::
61
59
]
62
60
63
61
64
-
---------
65
62
Rationale
66
-
---------
63
+
^^^^^^^^^
67
64
We need extended callable support, in order to inspect and produce callables via type-level computation. mypy supports `extended callables <https://mypy.readthedocs.io/en/stable/additional_features.html#extended-callable-types>`__ but they are deprecated in favor of callback protocols.
68
65
69
66
@@ -77,9 +74,8 @@ I am proposing a fully new extended callable syntax because:
77
74
4. I thought they were missing support for something but may have been wrong. They can handle positional-only.
It's important that there be a clearly specified type language for the type-level computation---we can't just be using some poorly specified subset of all Python.
85
81
@@ -124,9 +120,8 @@ It's important that there be a clearly specified type language for the type-leve
124
120
125
121
-----
126
122
127
-
==============
128
123
Type operators
129
-
==============
124
+
--------------
130
125
131
126
* ``GetArg[T, Base, Idx: Literal[str]]`` - returns the type argument number ``Idx`` to ``T`` when interpreted as ``Base``, or ``Never`` if it cannot be. (That is, if we have ``class A(B[C]): ...``, then ``GetArg[A, B, 0] == C`` while ``GetArg[A, A, 0] == Never``).
132
127
N.B: *Unfortunately* ``Base`` must be a proper class, *not* a protocol. So, for example, ``GetArg[Ty, Iterable, 0]]`` to get the type of something
@@ -138,9 +133,8 @@ Type operators
138
133
* ``FromUnion[T]`` - returns a tuple containing all of the union elements, or a 1-ary tuple containing T if it is not a union.
139
134
140
135
141
-
------------------------------
142
136
Object inspection and creation
143
-
------------------------------
137
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144
138
145
139
* ``NewProtocol[*Ps: Member]``
146
140
@@ -171,9 +165,8 @@ We also have helpers for extracting those names; they are all definable in terms
171
165
TODO: How should GetAttr interact with descriptors/classmethod? I am leaning towards it should apply the descriptor...
172
166
173
167
174
-
--------------------------------
175
168
Callable inspection and creation
176
-
--------------------------------
169
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
177
170
178
171
``Callable`` types always have their arguments exposed in the extended Callable format discussed above.
179
172
@@ -186,9 +179,8 @@ TODO: Should we make ``GetInit`` be literal types of default parameter values to
186
179
187
180
* ``Length[T: tuple]`` - get the length of a tuple as an int literal (or ``Literal[None]`` if it is unbounded)
188
181
189
-
---------
190
182
Annotated
191
-
---------
183
+
^^^^^^^^^
192
184
193
185
Libraries like FastAPI use annotations heavily, and we would like to be able to use annotations to drive type-level computation decision making.
194
186
@@ -208,9 +200,8 @@ We understand that this may be controversial, as currently Annotated may be full
208
200
DropAnnotations[int] = int
209
201
210
202
211
-
---------
212
203
InitField
213
-
---------
204
+
^^^^^^^^^
214
205
215
206
We want to be able to support transforming types based on dataclasses/attrs/pydantic style field descriptors. In order to do that, we need to be able to consume things like calls to ``Field``.
216
207
@@ -232,9 +223,8 @@ So if we write::
232
223
233
224
then we would infer the type ``InitField[TypedDict('...', {'default': Literal[0]})]`` for the initializer, and that would be made available as the ``Init`` field of the ``Member``.
234
225
235
-
-------------------
236
226
String manipulation
237
-
-------------------
227
+
^^^^^^^^^^^^^^^^^^^
238
228
239
229
String manipulation operations for string Literal types.
240
230
We can put more in, but this is what typescript has.
@@ -260,9 +250,8 @@ Two possibilities for creating parameterized functions/types. They are kind of m
260
250
261
251
How to *inspect* generic function types? Honestly, it doesn't really work in Typescript. Maybe we don't need to deal with it either.
262
252
263
-
=====================
264
253
Big (open?) questions
265
-
=====================
254
+
---------------------
266
255
267
256
1.
268
257
Can we actually implement Is (IsSubtype) at runtime in a satisfactory way? (PROBABLE DECISION: external library *and* restricted checking.)
0 commit comments