diff --git a/peps/pep-0827.rst b/peps/pep-0827.rst index ea1f36a3744..3a8fb89f854 100644 --- a/peps/pep-0827.rst +++ b/peps/pep-0827.rst @@ -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( @@ -1216,6 +1223,7 @@ We present implementations of a selection of them:: # Omit # 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 @@ -1224,6 +1232,27 @@ We present implementations of a selection of them:: ] ] + # Exclude + # 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 + # 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 # Constructs a type with all properties of T set to optional (T | None). type Partial[T] = typing.NewProtocol[