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
+22-1Lines changed: 22 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,10 +58,12 @@ only used for Any/All.
58
58
# TODO: New TypedDict setup
59
59
* ``NewProtocol[*Ps: Member]``
60
60
61
+
* ``Members[T]`` produces a ``tuple`` of ``Member`` types.
61
62
* ``Member[N: Literal & str, T]``
62
63
# These names are too long -- but we can't do ``Type`` !!
63
64
* ``GetName[T: Member]``
64
65
* ``GetType[T: Member]``
66
+
* Could we also put the defining type there??
65
67
66
68
---
67
69
@@ -89,27 +91,46 @@ We can put more in, but this is what typescript has.
89
91
90
92
Big open questions?
91
93
94
+
1.
92
95
Can we actually implement Is (IsSubtype) at runtime in a satisfactory way?
93
96
- Could we slightly dodge the question by *not* adding the evaluation library to the standard library, and letting the operations be opaque.
94
97
95
98
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?
96
99
97
-
There is a lot that needs to happen, like protocols and variance inference and
100
+
There is a lot that needs to happen, like protocols and variance inference and
98
101
callable subtyping (which might require matching against type vars...)
99
102
103
+
- 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.
104
+
105
+
- 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.
106
+
107
+
2.
100
108
How do we deal with modifiers? ClassVar, Final, Required, ReadOnly
101
109
- One option is to treat them not as types by as *modifiers* and have them
102
110
in a separate field where they are a union of Literals.
103
111
So ``x: Final[ClassVar[int]]`` would appear in ``Attrs`` as
This is kind of unsatisfying but I think it's probably right.
115
+
106
116
117
+
3.
107
118
How do we deal with Callables? We need to support extended callable syntax basically.
108
119
Or something like it.
109
120
121
+
4.
122
+
What do we do about ``Members`` on built-in types? ``typing.get_type_hints(int)`` returns ``{}`` but mypy will not agree!
123
+
124
+
An object of an empty user-defined class has 29 entries in ``dir`` (all dunders), and ``object()`` has 24. (In 3.14. In 3.12, it was 27 for the user-defined object).
110
125
111
126
=====
112
127
113
128
This proposal is less "well-typed" than typescript... (Well-kinded, maybe?)
114
129
Typescript has better typechecking at the alias definition site:
115
130
For ``P[K]``, ``K`` needs to have ``keyof P``...
131
+
132
+
Oh, we could maybe do better but it would require some new machinery.
133
+
* ``KeyOf[T]`` - literal keys of ``T``
134
+
* ``Member[T]``, when statically checking a type alias, could be treated as having some type like ``tuple[Member[KeyOf[T], object???, str], ...]``
135
+
* ``GetAttr[T, S: KeyOf[T]]`` - but this isn't supported yet. TS supports it.
136
+
* We would also need to do context sensitive type bound inference
0 commit comments