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
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
+
106
116
- Could we slightly dodge the question by *not* adding the evaluation library to the standard library, and letting the operations be opaque.
107
117
108
118
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?
109
119
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
-
113
120
- 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.
114
121
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.
116
125
Honestly this is basically what is currently implemented for the examples, so it is probably good enough.
117
126
118
127
It's unsatisfying, though.
119
128
120
129
2.
130
+
DECISION: quals string literals seems fine
131
+
121
132
How do we deal with modifiers? ClassVar, Final, Required, ReadOnly
122
133
- One option is to treat them not as types by as *modifiers* and have them
123
134
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
128
139
We could also have a ``MemberUpdate[M: Member, T]`` that updates
129
140
the type of a member but preserves its name and modifiers.
130
141
131
-
-
142
+
- Otherwise need to treat them as types.
132
143
133
144
134
145
3.
@@ -143,7 +154,10 @@ An object of an empty user-defined class has 29 entries in ``dir`` (all dunders)
143
154
5.
144
155
Polymorphic callables? How do we represent their type and how do we construct their type?
145
156
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.
147
161
148
162
=====
149
163
@@ -152,6 +166,7 @@ Typescript has better typechecking at the alias definition site:
152
166
For ``P[K]``, ``K`` needs to have ``keyof P``...
153
167
154
168
Oh, we could maybe do better but it would require some new machinery.
169
+
155
170
* ``KeyOf[T]`` - literal keys of ``T``
156
171
* ``Member[T]``, when statically checking a type alias, could be treated as having some type like ``tuple[Member[KeyOf[T], object???, str], ...]``
157
172
* ``GetAttr[T, S: KeyOf[T]]`` - but this isn't supported yet. TS supports it.
0 commit comments