Skip to content

Commit c3dd997

Browse files
committed
More PEP notes
1 parent 9da49a7 commit c3dd997

1 file changed

Lines changed: 27 additions & 21 deletions

File tree

pep.rst

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ We can then do::
323323
# err1 + err2 # E: Broadcast mismatch: Literal[2], Literal[3]
324324

325325

326-
TODO: Link the implementation
326+
(Example code for implementing this :ref:`below <numpy-impl>`.)
327327

328328

329-
Specification of Needed Preliminaries
330-
=====================================
329+
Specification of Some Prerequisites
330+
===================================
331331

332332
(Some content is still in `spec-draft.rst <spec-draft.rst>`_).
333333

@@ -350,8 +350,7 @@ Here ``BaseTypedDict`` is defined as::
350350
class BaseTypedDict(typing.TypedDict):
351351
pass
352352

353-
But any typeddict would be allowed there. (TODO: Or maybe we should
354-
allow ``dict``?)
353+
But any typeddict would be allowed there.
355354

356355
Then, if we had a call like::
357356

@@ -627,13 +626,13 @@ Basic operators
627626
member named ``S`` from the class ``T``.
628627

629628

630-
* ``GetSpecialAttr[T: type, Attr: Literal[str]]``: Extract the value
629+
* ``GetSpecialAttr[T: type, Attr: Literal[str]]``: Extracts the value
631630
of special attribute named ``Attr`` from the class ``T``. Valid
632631
attributes are ``__name__``, ``__module__``, and ``__qualname__``.
633632
Returns the value as a ``Literal[str]``.
634633

635634

636-
* ``Length[T: tuple]`` - get the length of a tuple as an int literal
635+
* ``Length[T: tuple]`` - Gets the length of a tuple as an int literal
637636
(or ``Literal[None]`` if it is unbounded)
638637

639638

@@ -643,7 +642,7 @@ All of the operators in this section are :ref:`lifted over union types
643642
Union processing
644643
''''''''''''''''
645644

646-
* ``FromUnion[T]``: returns a tuple containing all of the union
645+
* ``FromUnion[T]``: Returns a tuple containing all of the union
647646
elements, or a 1-ary tuple containing T if it is not a union.
648647

649648
* ``Union[*Ts]``: ``Union`` will become able to take variadic
@@ -711,13 +710,15 @@ All of the operators in this section are :ref:`lifted over union types
711710
Object creation
712711
'''''''''''''''
713712

714-
* ``NewProtocol[*Ps: Member]``
713+
* ``NewProtocol[*Ms: Member]``: Create a new structural protocol with members
714+
specified by ``Member`` arguments
715715

716716
* ``NewProtocolWithBases[Bases, Ps: tuple[Member]]`` - A variant that
717-
allows specifying bases too. (UNIMPLEMENTED) - OR MAYBE SHOULD NOT EXIST
717+
allows specifying bases too. TODO: Is this something we actually want?
718718

719-
* ``NewTypedDict[*Ps: Member]`` -- TODO: Needs fleshing out; will work
720-
similarly to ``NewProtocol`` but has different flags
719+
* ``NewTypedDict[*Ps: Member]`` - Creates a new ``TypedDict`` with
720+
items specified by the ``Member`` arguments. TODO: Do we want a way
721+
to specify ``extra_items``?
721722

722723

723724
N.B: Currently we aren't proposing any way to create nominal classes
@@ -818,9 +819,6 @@ etc).
818819
(This is a little unsatisfying. Rationale discussed :ref:`below
819820
<generic-callable-rationale>`.)
820821

821-
822-
(LAMBDA PART NOT IMPLEMENTED YET)
823-
824822
TODO: Decide if we have any mechanisms to inspect/destruct
825823
``GenericCallable``. Maybe can fetch the variable information and
826824
maybe can apply it to concrete types?
@@ -1258,12 +1256,12 @@ we encounter a variable.)
12581256

12591257

12601258
The reason we suggest restricting the use of ``GenericCallable`` to
1261-
the type argument of ``Member`` is because full impredicative
1262-
polymorphism (where you can have generic type binding nested inside
1263-
types and you can instantiate type variables with other generic types)
1264-
is an big can of worms when combined with type inference (TODO: CITE).
1265-
While it would be nice to support, we don't want to
1266-
open that can of worms now.
1259+
the type argument of ``Member`` is because impredicative
1260+
polymorphism (where you you can instantiate type variables with other
1261+
generic types) and rank-N types (where generics can be bound in nested
1262+
positions deep inside function types) are cans of worms when combined
1263+
with type inference [#undecidable]_. While it would be nice to support,
1264+
we don't want to open that can of worms now.
12671265

12681266

12691267
The unbound type variable tuple is so that bounds and defaults and
@@ -1450,7 +1448,15 @@ Footnotes
14501448
.. [#ref-impl] https://github.com/msullivan/mypy/tree/typemap
14511449
.. [#runtime] https://github.com/vercel/python-typemap/
14521450
.. [#survey] https://engineering.fb.com/2025/12/22/developer-tools/python-typing-survey-2025-code-quality-flexibility-typing-adoption/
1451+
.. [#undecidable]
1452+
1453+
* "Partial polymorphic type inference is undecidable" by Hans Boehm: https://dl.acm.org/doi/10.1109/SFCS.1985.44
1454+
* "On the Undecidability of Partial Polymorphic Type Reconstruction" by Frank Pfenning: https://www.cs.cmu.edu/~fp/papers/CMU-CS-92-105.pdf
14531455

1456+
Our setting does not try to infer generic types for functions,
1457+
though, which might dodge some of the problems. On the other hand,
1458+
we have subtyping. (Honestly we are already pretty deep into some
1459+
of these cans of worms.)
14541460

14551461

14561462
Copyright

0 commit comments

Comments
 (0)