Skip to content

Commit b5dd144

Browse files
committed
Fix some formatting issues in spec-draft.rst
1 parent 0bef050 commit b5dd144

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

spec-draft.rst

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ only used for Any/All.
5656

5757
# TODO: NewProtocol needs a way of doing bases also...
5858
# TODO: New TypedDict setup
59+
5960
* ``NewProtocol[*Ps: Member]``
6061

6162
* ``Members[T]`` produces a ``tuple`` of ``Member`` types.
6263
* ``Member[N: Literal[str], T, Q: Quals, D]``
64+
6365
# These names are too long -- but we can't do ``Type`` !!
66+
# Kind of want to do the *longer* ``MemberName``
67+
6468
* ``GetName[T: Member]``
6569
* ``GetType[T: Member]``
6670
* ``GetQuals[T: Member]``
@@ -72,11 +76,12 @@ only used for Any/All.
7276
* ``GetAttr[T, S: Literal[str]]``
7377

7478
# TODO: how to deal with special forms like Callable and tuple[T, ...]
79+
7580
* ``GetArgs[T]`` - returns a tuple containing all of the type arguments
7681
* ``FromUnion[T]`` - returns a tuple containing all of the union
7782
elements, or a 1-ary tuple containing T if it is not a union.
7883

79-
# TODO: How to do IsUnion?
84+
# TODO: How to do IsUnion? Might need a ``Length`` for tuples?
8085

8186

8287
String manipulation operations for string Literal types.
@@ -102,22 +107,28 @@ bunch of conditionals.
102107
Big open questions?
103108

104109
1.
110+
PROBABLE DECISION: external library *and* restricted checking.
111+
105112
Can we actually implement Is (IsSubtype) at runtime in a satisfactory way?
113+
- There is a lot that needs to happen, like protocols and variance inference and callable subtyping (which might require matching against type vars...)
114+
Jukka points out that lots of type information is frequently missing at runtime too: attributes are frequently unannotated and
115+
106116
- Could we slightly dodge the question by *not* adding the evaluation library to the standard library, and letting the operations be opaque.
107117

108118
Then we would promise to have a third-party library, which would need to be "fit for purpose" for people to want to use, but would be free of the burden of being canonical?
109119

110-
There is a lot that needs to happen, like protocols and variance inference and
111-
callable subtyping (which might require matching against type vars...)
112-
113120
- I think we probably *can't* try to put it in the standard library. I think it would by nature bless the implementation with some degree of canonicity that I'm not sure we can back up. Different typecheckers don't always match on subtyping behavior, *and* it sometimes depends on config flags (like strict_optional in mypy). *And* we could imagine a bunch of other config flags: whether to be strict about argument names in protocols, for example.
114121

115-
- We can instead have something simpler, which I will call ``Matches``. ``Matches`` would do *simple* checking of the *head* of types, essentially, without looking at type parameters. It would still lift over unions and would check literals.
122+
- We can instead have something simpler, which I will call ``IsSubSimilar``. ``IsSubSimilar`` would do *simple* checking of the *head* of types, essentially, without looking at type parameters. It would still lift over unions and would check literals.
123+
124+
Probably need a better name.
116125
Honestly this is basically what is currently implemented for the examples, so it is probably good enough.
117126

118127
It's unsatisfying, though.
119128

120129
2.
130+
DECISION: quals string literals seems fine
131+
121132
How do we deal with modifiers? ClassVar, Final, Required, ReadOnly
122133
- One option is to treat them not as types by as *modifiers* and have them
123134
in a separate field where they are a union of Literals.
@@ -128,7 +139,7 @@ How do we deal with modifiers? ClassVar, Final, Required, ReadOnly
128139
We could also have a ``MemberUpdate[M: Member, T]`` that updates
129140
the type of a member but preserves its name and modifiers.
130141

131-
-
142+
- Otherwise need to treat them as types.
132143

133144

134145
3.
@@ -143,7 +154,10 @@ An object of an empty user-defined class has 29 entries in ``dir`` (all dunders)
143154
5.
144155
Polymorphic callables? How do we represent their type and how do we construct their type?
145156

146-
What does TS do here? - TS has full impredactive polymorphic functions. You can do System F stuff.
157+
What does TS do here? - TS has full impredactive polymorphic functions. You can do System F stuff. *But* trying to do type level operations on them seems to lose track of the polymorphism: the type vars will get instantiated with ``unknown``.
158+
159+
6.
160+
Want to be graceful at runtime, since **many** classes don't have full annotations.
147161

148162
=====
149163

@@ -152,6 +166,7 @@ Typescript has better typechecking at the alias definition site:
152166
For ``P[K]``, ``K`` needs to have ``keyof P``...
153167

154168
Oh, we could maybe do better but it would require some new machinery.
169+
155170
* ``KeyOf[T]`` - literal keys of ``T``
156171
* ``Member[T]``, when statically checking a type alias, could be treated as having some type like ``tuple[Member[KeyOf[T], object???, str], ...]``
157172
* ``GetAttr[T, S: KeyOf[T]]`` - but this isn't supported yet. TS supports it.

0 commit comments

Comments
 (0)