Skip to content

Commit 20cc2c5

Browse files
committed
Proofreading tweaks
1 parent f975066 commit 20cc2c5

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

pep.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ system, some libraries come with custom mypy plugins (though then
3636
other typecheckers suffer). The case of dataclass-like transformations
3737
was considered common enough that a special-case
3838
``@dataclass_transform`` decorator was added specifically to cover
39-
that case (:pep:`PEP 681 <681>`).
39+
that case (:pep:`681`).
4040

4141
We are proposing to add to the type system type manipulation
4242
facilities that are more capable of keeping up with dynamic Python
@@ -247,7 +247,7 @@ This kind of pattern is widespread enough that :pep:`PEP 681 <681>`
247247
was created to represent a lowest-common denominator subset of what
248248
existing libraries do.
249249

250-
Make it possible for libraries to implement more of these patterns
250+
Making it possible for libraries to implement more of these patterns
251251
directly in the type system will give better typing without needing
252252
further special casing, typechecker plugins, hardcoded support, etc.
253253

@@ -258,7 +258,7 @@ More powerful decorator typing
258258

259259
The typing of decorator functions has long been a pain point in Python
260260
typing. The situation was substantially improved by the introducing of
261-
``ParamSpec`` in :pep:`PEP 612 <612>`, but a number of patterns remain
261+
``ParamSpec`` in :pep:`612`, but a number of patterns remain
262262
unsupported:
263263

264264
* Adding/removing/modifying a keyword parameter
@@ -273,7 +273,7 @@ NumPy-style broadcasting
273273
------------------------
274274

275275
One of the motivations for the introduction of ``TypeVarTuple`` in
276-
:pep:`PEP 646 <646>` is to represent the shapes of multi-dimensional
276+
:pep:`646` is to represent the shapes of multi-dimensional
277277
arrays, such as::
278278

279279
x: Array[float, L[480], L[640]] = Array()
@@ -351,7 +351,7 @@ Then, if we had a call like::
351351

352352
the type inferred for ``K`` would be something like::
353353

354-
TypedDict({'x': int, y: list[str]})
354+
TypedDict({'x': int, 'y': list[str]})
355355

356356
This is basically a combination of
357357
"PEP 692 – Using TypedDict for more precise ``**kwargs`` typing"
@@ -1043,13 +1043,11 @@ contains all the ``Property`` attributes of ``T``.
10431043

10441044
::
10451045

1046-
type PropsOnly[T] = list[
1047-
typing.NewProtocol[
1048-
*[
1049-
typing.Member[typing.GetName[p], PointerArg[typing.GetType[p]]]
1050-
for p in typing.Iter[typing.Attrs[T]]
1051-
if typing.IsSub[typing.GetType[p], Property]
1052-
]
1046+
type PropsOnly[T] = typing.NewProtocol[
1047+
*[
1048+
typing.Member[typing.GetName[p], PointerArg[typing.GetType[p]]]
1049+
for p in typing.Iter[typing.Attrs[T]]
1050+
if typing.IsSub[typing.GetType[p], Property]
10531051
]
10541052
]
10551053

tests/test_qblike_2.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,11 @@ def select[ModelT, K: typing.BaseTypedDict](
110110
contains all the ``Property`` attributes of ``T``.
111111
112112
"""
113-
type PropsOnly[T] = list[
114-
typing.NewProtocol[
115-
*[
116-
typing.Member[typing.GetName[p], PointerArg[typing.GetType[p]]]
117-
for p in typing.Iter[typing.Attrs[T]]
118-
if typing.IsSub[typing.GetType[p], Property]
119-
]
113+
type PropsOnly[T] = typing.NewProtocol[
114+
*[
115+
typing.Member[typing.GetName[p], PointerArg[typing.GetType[p]]]
116+
for p in typing.Iter[typing.Attrs[T]]
117+
if typing.IsSub[typing.GetType[p], Property]
120118
]
121119
]
122120

@@ -150,7 +148,7 @@ class User:
150148

151149
name: Property[str]
152150
email: Property[str]
153-
posts: Link[Post]
151+
posts: MultiLink[Post]
154152

155153

156154
def test_qblike2_1():
@@ -202,3 +200,24 @@ class PropsOnly[tests.test_qblike_2.Post]:
202200
title: str
203201
content: str
204202
""")
203+
204+
205+
def test_qblike2_3():
206+
ret = eval_call(
207+
select,
208+
Post,
209+
title=True,
210+
comments=True,
211+
author=True,
212+
)
213+
214+
assert ret.__origin__ is list
215+
ret = ret.__args__[0]
216+
fmt = format_helper.format_class(ret)
217+
218+
assert fmt == textwrap.dedent("""\
219+
class select[...]:
220+
title: str
221+
comments: list[tests.test_qblike_2.PropsOnly[tests.test_qblike_2.Comment]]
222+
author: tests.test_qblike_2.PropsOnly[tests.test_qblike_2.Comment]
223+
""")

0 commit comments

Comments
 (0)