Skip to content

Commit b859937

Browse files
committed
Spec work
1 parent 9d7a00f commit b859937

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

spec-draft.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ We introduce a ``Param`` type the contains all the information about a function
3232
ParamQuals = typing.Literal["*", "**", "default", "keyword"]
3333

3434
And then, we can represent the type of a function like::
35+
3536
def func(
3637
a: int,
3738
/,
@@ -169,6 +170,19 @@ We also have helpers for extracting those names; they are all definable in terms
169170
TODO: How should GetAttr interact with descriptors/classmethod? I am leaning towards it should apply the descriptor...
170171

171172

173+
--------------------------------
174+
Callable inspection and creation
175+
--------------------------------
176+
177+
* TODO: Should ``GetArg`` on a callable automatically convert ``[int, str]`` or whatever into something using ``Param``? Or should a separate operator be needed?
178+
179+
* ``GetParamName[T: Param]``
180+
* ``GetParamType[T: Param]``
181+
* ``GetParamQuals[T: Param]``
182+
183+
This is unsatisfying; maybe they all need to be just ``ParamName`` and also ``MemberName`` above.
184+
We could also merge the getters for ``Param`` and ``Member``.
185+
172186
----
173187

174188
* ``Length[T: tuple]`` - get the length of a tuple as an int literal (or ``Literal[None]`` if it is unbounded)
@@ -179,7 +193,7 @@ String manipulation operations for string Literal types.
179193
We can put more in, but this is what typescript has.
180194
``Slice`` and ``Concat`` are a poor man's literal template.
181195
We can actually implement the case functions in terms of them and a
182-
bunch of conditionals.
196+
bunch of conditionals, but shouldn't (especially if we want it to work for all unicode!).
183197

184198
-------------------
185199
String manipulation
@@ -197,6 +211,7 @@ String manipulation
197211
----
198212

199213
Two possibilities for creating parameterized functions/types. They are kind of more syntax than functions exactly. I like the lambda one more.
214+
200215
* ``NewParameterized[V, Ty]`` - ``V`` should be a ``TypeVar`` (ugh!) and ``Ty`` should be a ``Callable`` or a ``NewProtocol`` or some such.
201216
* ``NewParameterized[lambda v: Ty]`` - The lambda could take multiple params, and introduce multiple variables. The biggest snag is how to specify bounds; one option is via default arguments.
202217

typemap/typing.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ class Member[N: str, T, Q: MemberQuals = typing.Never, D = typing.Never]:
3030
type GetDefiner[T: Member] = GetArg[T, Member, 3] # type: ignore[valid-type]
3131

3232

33-
class Attrs[T]:
33+
ParamQuals = typing.Literal["*", "**", "="]
34+
35+
36+
class Param[N: str | None, T, Q: ParamQuals = typing.Never]:
3437
pass
3538

3639

37-
ParamQuals = typing.Literal["*", "**", "="]
40+
type GetParamName[T: Param] = GetArg[T, Param, 0] # type: ignore[valid-type]
41+
type GetParamType[T: Param] = GetArg[T, Param, 1] # type: ignore[valid-type]
42+
type GetParamQuals[T: Param] = GetArg[T, Param, 2] # type: ignore[valid-type]
3843

3944

40-
class Param[N: str | None, T, Q: ParamQuals = typing.Never]:
45+
class Attrs[T]:
4146
pass
4247

4348

0 commit comments

Comments
 (0)