Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions peps/pep-0827.rst
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,15 @@ Union processing
* ``FromUnion[T]``: Returns a tuple containing all of the union
elements, or a 1-ary tuple containing T if it is not a union.

The union should first be simplified by removing elements that are
subtypes of other elements, but *not* by replacing ``Literal[True,
False]`` with ``bool`` or vice-versa or similar.

The goal here is to make it possible to lift operations over
unions. Care ought to be taken when using this, since the particular
order of elements is not specified; typically the result of the iteration
should be unpacked into another union immediately.

* ``Union[*Ts]``: ``Union`` will become able to take variadic
arguments, so that it can take unpacked comprehension arguments.

Expand All @@ -677,6 +686,11 @@ Object inspection
* ``Members[T]``: produces a ``tuple`` of ``Member`` types describing
the members (attributes and methods) of class or typed dict ``T``.

Properties should be returned as ``property`` types, which we should
make generic and parameterized over both the getter and setter
types. (Under discussion in `typeshed issue #4731
<https://github.com/python/typeshed/issues/4731>`__)

In order to allow typechecking time and runtime evaluation to
coincide more closely, **only members with explicit type annotations
are included**. (This is intended to also exclude unannotated
Expand Down Expand Up @@ -1846,6 +1860,19 @@ Open Issues
Arguably, though, we would like ``tuple[Any | None, ...]`` as the result,
which would require some more careful thought to specify.

* Would intersection types conflict with any of this, if they are
added? Would it be sufficient to just specify how existing operators
should handle it (probably including that intersections should be
distributed over unions when doing ``FromUnion``, I'd guess, like TS
does for conditional types)? We could potentially add
``FromIntersection``, but intersections simplify aggressively and it
is not clear it would be sensical. TypeScript does not have an
equivalent.

* Should ``GetMemberType`` follow the descriptor protocol,
``__getattr__``, etc? (Currently the behavior is for it to
behave mostly like ``GetMember[T, S].type``.)


Acknowledgements
================
Expand Down
Loading