Skip to content

Commit e5a2be2

Browse files
committed
Tweak draft headings
1 parent 816db86 commit e5a2be2

1 file changed

Lines changed: 11 additions & 22 deletions

File tree

spec-draft.rst

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
===================================
21
Unpack of typevars for ``**kwargs``
3-
===================================
2+
-----------------------------------
43

54
A minor proposal that could be split out maybe:
65

@@ -20,9 +19,8 @@ This is basically a combination of "PEP 692 – Using TypedDict for more precise
2019
2120
This is potentially moderately useful on its own but is being done to support processing **kwargs with type level computation.
2221
23-
==========================
2422
Extended Callables, take 2
25-
==========================
23+
--------------------------
2624

2725
We introduce a ``Param`` type the contains all the information about a function param::
2826

@@ -61,9 +59,8 @@ as (we are omiting the ``Literal`` in places)::
6159
]
6260

6361

64-
---------
6562
Rationale
66-
---------
63+
^^^^^^^^^
6764
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.
6865

6966

@@ -77,9 +74,8 @@ I am proposing a fully new extended callable syntax because:
7774
4. I thought they were missing support for something but may have been wrong. They can handle positional-only.
7875

7976

80-
============================================================
8177
Grammar specification of the extensions to the type language
82-
============================================================
78+
------------------------------------------------------------
8379

8480
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.
8581

@@ -124,9 +120,8 @@ It's important that there be a clearly specified type language for the type-leve
124120

125121
-----
126122

127-
==============
128123
Type operators
129-
==============
124+
--------------
130125

131126
* ``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``).
132127
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
138133
* ``FromUnion[T]`` - returns a tuple containing all of the union elements, or a 1-ary tuple containing T if it is not a union.
139134

140135

141-
------------------------------
142136
Object inspection and creation
143-
------------------------------
137+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144138

145139
* ``NewProtocol[*Ps: Member]``
146140

@@ -171,9 +165,8 @@ We also have helpers for extracting those names; they are all definable in terms
171165
TODO: How should GetAttr interact with descriptors/classmethod? I am leaning towards it should apply the descriptor...
172166

173167

174-
--------------------------------
175168
Callable inspection and creation
176-
--------------------------------
169+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
177170

178171
``Callable`` types always have their arguments exposed in the extended Callable format discussed above.
179172

@@ -186,9 +179,8 @@ TODO: Should we make ``GetInit`` be literal types of default parameter values to
186179

187180
* ``Length[T: tuple]`` - get the length of a tuple as an int literal (or ``Literal[None]`` if it is unbounded)
188181

189-
---------
190182
Annotated
191-
---------
183+
^^^^^^^^^
192184

193185
Libraries like FastAPI use annotations heavily, and we would like to be able to use annotations to drive type-level computation decision making.
194186

@@ -208,9 +200,8 @@ We understand that this may be controversial, as currently Annotated may be full
208200
DropAnnotations[int] = int
209201

210202

211-
---------
212203
InitField
213-
---------
204+
^^^^^^^^^
214205

215206
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``.
216207

@@ -232,9 +223,8 @@ So if we write::
232223

233224
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``.
234225

235-
-------------------
236226
String manipulation
237-
-------------------
227+
^^^^^^^^^^^^^^^^^^^
238228

239229
String manipulation operations for string Literal types.
240230
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
260250

261251
How to *inspect* generic function types? Honestly, it doesn't really work in Typescript. Maybe we don't need to deal with it either.
262252

263-
=====================
264253
Big (open?) questions
265-
=====================
254+
---------------------
266255

267256
1.
268257
Can we actually implement Is (IsSubtype) at runtime in a satisfactory way? (PROBABLE DECISION: external library *and* restricted checking.)

0 commit comments

Comments
 (0)