Skip to content

Commit 3d40b83

Browse files
authored
edits (#107)
1 parent 6a40c47 commit 3d40b83

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

pep.rst

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ perform complex metaprogramming, especially in libraries and
2929
frameworks. The type system typically cannot model metaprogramming.
3030

3131
To bridge the gap between metaprogramming and the type
32-
system, some libraries come with custom mypy plugins (though then
33-
other typecheckers suffer). The case of dataclass-like transformations
32+
system, some libraries come with custom mypy plugins.
33+
The case of dataclass-like transformations
3434
was considered common enough that a special-case
3535
``@dataclass_transform`` decorator was added specifically to cover
3636
that case (:pep:`681`). The problem with this approach is that many
@@ -62,7 +62,9 @@ Prisma-style ORMs
6262

6363
`Prisma <#prisma_>`_, a popular ORM for TypeScript, allows writing
6464
database queries in TypeScript like
65-
(adapted from `this example <#prisma-example_>`_)::
65+
(adapted from `this example <#prisma-example_>`_):
66+
67+
.. code-block:: typescript
6668
6769
const user = await prisma.user.findMany({
6870
select: {
@@ -72,7 +74,9 @@ database queries in TypeScript like
7274
},
7375
});
7476
75-
for which the inferred type of ``user`` will be something like::
77+
for which the inferred type of ``user`` will be something like:
78+
79+
.. code-block:: typescript
7680
7781
{
7882
email: string;
@@ -88,7 +92,7 @@ for which the inferred type of ``user`` will be something like::
8892
Here, the output type is an intersection of the existing information
8993
about the type of ``prisma.user`` (a TypeScript type reflected from
9094
the database ``user`` table) and the type of the argument to
91-
the ``findMany`` method. It returns an array of objects containing
95+
the ``findMany()`` method. It returns an array of objects containing
9296
the properties of ``user`` that were explicitly requested;
9397
where ``posts`` is a "relation" referencing another type.
9498

@@ -141,7 +145,8 @@ would have a dynamically computed return type ``list[<User>]`` where::
141145
content: str
142146

143147
Even further, an IDE could offer code completion for
144-
all arguments of the ``db.select()`` call, recursively.
148+
all arguments of the ``db.select()`` call (matching the
149+
actual database column names), recursively.
145150

146151
(Example code for implementing this :ref:`below <qb-impl>`.)
147152

@@ -152,7 +157,7 @@ Automatically deriving FastAPI CRUD models
152157
In the `FastAPI tutorial <#fastapi-tutorial_>`_, they show how to
153158
build CRUD endpoints for a simple ``Hero`` type. At its heart is a
154159
series of class definitions used both to define the database interface
155-
and to perform validation/filtering of the data in the endpoint::
160+
and to perform validation and filtering of the data in the endpoint::
156161

157162
class HeroBase(SQLModel):
158163
name: str = Field(index=True)
@@ -251,9 +256,8 @@ dataclasses-style method generation
251256

252257
We would additionally like to be able to generate method signatures
253258
based on the attributes of an object. The most well-known example of
254-
this is probably generating ``__init__`` methods for dataclasses,
255-
which we present a simplified example of. (In our test suites, this is
256-
merged with the FastAPI-style example above, but it need not be).
259+
this is generating ``__init__`` methods for dataclasses,
260+
which we present a simplified example of.
257261

258262
This kind of pattern is widespread enough that :pep:`PEP 681 <681>`
259263
was created to represent a lowest-common denominator subset of what
@@ -345,9 +349,8 @@ Extended Callables
345349
------------------
346350

347351
We introduce a new extended callable proposal for expressing arbitrarily
348-
complex callable types. The goal here is not really to produce a new
349-
syntax to write in annotations (it seems less pleasant to write than
350-
callback protocols are), but to provide a way of constructing the types
352+
complex callable types. The goal here is not to have a new
353+
syntax to write in annotations, but to provide a way of constructing the types
351354
that is amenable to creating and introspecting callable types using
352355
the other features of this PEP.
353356

@@ -538,16 +541,15 @@ members and function params have "associated" type members, which can
538541
be accessed by dot notation: ``m.name``, ``m.type``, etc.
539542

540543
This operation is not lifted over union types. Using it on the wrong
541-
sort of type will be an error. (At least, it must be that way at
542-
runtime, and we probably want typechecking to match.)
544+
sort of type will be an error. It must be that way at runtime,
545+
and we want typechecking to match.
543546

544547

545548
Type operators
546549
--------------
547550

548-
In some sections below we write things like ``Literal[int]`` to mean
549-
"a literal that is of type ``int``". I don't think I'm really
550-
proposing to add that as a notion, but we could.
551+
Note that in some sections below we write things like ``Literal[int]`` to mean
552+
"a literal that is of type ``int``".
551553

552554
.. _boolean-ops:
553555

@@ -557,8 +559,8 @@ Boolean operators
557559
* ``IsAssignable[T, S]``: Returns a boolean literal type indicating whether
558560
``T`` is assignable to ``S``.
559561

560-
(That is, it is a "consistent subtype". This is subtyping extended
561-
to gradual types.)
562+
That is, it is a "consistent subtype". This is subtyping extended
563+
to gradual types.
562564

563565
* ``IsEquivalent[T, S]``:
564566
Equivalent to ``IsAssignable[T, S] and IsAssignable[S, T]``.
@@ -678,8 +680,6 @@ Object creation
678680
* ``NewTypedDict[*Ps: Member]`` - Creates a new ``TypedDict`` with
679681
items specified by the ``Member`` arguments.
680682

681-
.. TODO: Do we want a way to specify ``extra_items``?
682-
683683
Note that we are not currently proposing any way to create *nominal* classes
684684
or any way to make new *generic* types.
685685

@@ -767,9 +767,6 @@ Raise error
767767
Update class
768768
''''''''''''
769769

770-
N.B: This is kind of sketchy but it is I think needed for defining
771-
base classes and type decorators that do ``dataclass`` like things.
772-
773770
* ``UpdateClass[*Ps: Member]``: A special form that *updates* an
774771
existing nominal class with new members (possibly overriding old
775772
ones, or removing them by making them have type ``Never``).

0 commit comments

Comments
 (0)