Skip to content

Commit df07160

Browse files
committed
More thinking
1 parent 6af9878 commit df07160

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

spec-draft.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ only used for Any/All.
5858
# TODO: New TypedDict setup
5959
* ``NewProtocol[*Ps: Member]``
6060

61+
* ``Members[T]`` produces a ``tuple`` of ``Member`` types.
6162
* ``Member[N: Literal & str, T]``
6263
# These names are too long -- but we can't do ``Type`` !!
6364
* ``GetName[T: Member]``
6465
* ``GetType[T: Member]``
66+
* Could we also put the defining type there??
6567

6668
---
6769

@@ -89,27 +91,46 @@ We can put more in, but this is what typescript has.
8991

9092
Big open questions?
9193

94+
1.
9295
Can we actually implement Is (IsSubtype) at runtime in a satisfactory way?
9396
- Could we slightly dodge the question by *not* adding the evaluation library to the standard library, and letting the operations be opaque.
9497

9598
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?
9699

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
98101
callable subtyping (which might require matching against type vars...)
99102

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.
100108
How do we deal with modifiers? ClassVar, Final, Required, ReadOnly
101109
- One option is to treat them not as types by as *modifiers* and have them
102110
in a separate field where they are a union of Literals.
103111
So ``x: Final[ClassVar[int]]`` would appear in ``Attrs`` as
104112
``Member[Literal['x'], int, Literal['Final' | 'ClassVar']]``
105113

114+
This is kind of unsatisfying but I think it's probably right.
115+
106116

117+
3.
107118
How do we deal with Callables? We need to support extended callable syntax basically.
108119
Or something like it.
109120

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).
110125

111126
=====
112127

113128
This proposal is less "well-typed" than typescript... (Well-kinded, maybe?)
114129
Typescript has better typechecking at the alias definition site:
115130
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

Comments
 (0)