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
29 changes: 29 additions & 0 deletions peps/pep-0827.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,16 @@ the database) like::
id: Property[int]

name: Property[str]
age: Property[int | None]
email: Property[str]
posts: Link[Post]


(In the example, ``Property`` indicates a scalar type, ``Link``
indicates a reference to another table, and ``MultiLink`` indicates a
potentially many-to-many reference to another table; all would be
defined by the ORM library.)

So, in Python code, a call like::

db.select(
Expand Down Expand Up @@ -1216,6 +1223,7 @@ We present implementations of a selection of them::

# Omit<T, Keys>
# Constructs a type by picking all properties from T and then removing Keys.
# Note that unlike in TS, our Omit does not depend on Exclude.
type Omit[T, Keys] = typing.NewProtocol[
*[
p
Expand All @@ -1224,6 +1232,27 @@ We present implementations of a selection of them::
]
]

# Exclude<T, U>
# Constructs a type by excluding from T all union members assignable to U.
type Exclude[T, U] = Union[
*[
x
for x in typing.Iter[typing.FromUnion[T]]
if not typing.IsAssignable[x, U]
]
]

# Extract<T, U>
# Constructs a type by extracting from T all union members assignable to U.
type Extract[T, U] = Union[
*[
x
for x in typing.Iter[typing.FromUnion[T]]
# Just the inverse of Exclude, really
if typing.IsAssignable[x, U]
]
]

# Partial<T>
# Constructs a type with all properties of T set to optional (T | None).
type Partial[T] = typing.NewProtocol[
Expand Down
Loading