@@ -43,13 +43,14 @@ should ignore it and simply treat the type as ``T``. Unlike the
43
43
``no_type_check `` functionality that currently exists in the ``typing ``
44
44
module which completely disables typechecking annotations on a function
45
45
or a class, the ``Annotated `` type allows for both static typechecking
46
- of ``T `` (e.g., via mypy [mypy ]_ or Pyre [pyre ]_, which can safely ignore ``x ``)
46
+ of ``T `` (e.g., via `mypy <mypy _>`_ or `Pyre <pyre _>`_,
47
+ which can safely ignore ``x ``)
47
48
together with runtime access to ``x `` within a specific application. The
48
49
introduction of this type would address a diverse set of use cases of interest
49
50
to the broader Python community.
50
51
51
- This was originally brought up as issue 600 [ issue-600 ] _ in the typing github
52
- and then discussed in Python ideas [ python-ideas ] _.
52
+ This was originally brought up as ` issue 600 < issue-600 _>` _ in the typing github
53
+ and then discussed in ` Python ideas < python-ideas _>` _.
53
54
54
55
Motivating examples
55
56
-------------------
@@ -81,21 +82,21 @@ Lowering barriers to developing new typing constructs
81
82
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82
83
83
84
Typically when adding a new type, a developer need to upstream that type to the
84
- typing module and change mypy, PyCharm [ pycharm ] _, Pyre, pytype [ pytype ] _,
85
+ typing module and change mypy, ` PyCharm < pycharm _>` _, Pyre, ` pytype < pytype _>` _,
85
86
etc...
86
87
This is particularly important when working on open-source code that
87
88
makes use of these types, seeing as the code would not be immediately
88
89
transportable to other developers' tools without additional logic. As a result,
89
90
there is a high cost to developing and trying out new types in a codebase.
90
91
Ideally, authors should be able to introduce new types in a manner that allows
91
- for graceful degradation (e.g.: when clients do not have a custom mypy plugin
92
- [ mypy-plugin ] _), which would lower the barrier to development and ensure some
92
+ for graceful degradation (e.g.: when clients do not have a custom ` mypy plugin
93
+ < mypy-plugin_> ` _), which would lower the barrier to development and ensure some
93
94
degree of backward compatibility.
94
95
95
- For example, suppose that an author wanted to add support for tagged unions
96
- [ tagged-union ] _ to Python. One way to accomplish would be to annotate
97
- `` TypedDict `` [ typed-dict ]_ in Python such that only one field is allowed to be
98
- set::
96
+ For example, suppose that an author wanted to add support for ` tagged unions
97
+ < tagged-union_> ` _ to Python. One way to accomplish would be to ` annotate
98
+ <typed-dict_> `_ `` TypedDict `` in Python such that only one field is allowed
99
+ to be set::
99
100
100
101
Currency = Annotated[
101
102
TypedDict('Currency', {'dollars': float, 'pounds': float}, total=False),
@@ -236,7 +237,7 @@ cause ``Annotated`` to not integrate cleanly with the other typing annotations:
236
237
* ``Annotated `` cannot infer the decorated type. You could imagine that
237
238
``Annotated[..., Immutable] `` could be used to mark a value as immutable
238
239
while still inferring its type. Typing does not support using the
239
- inferred type anywhere else [ issue-276 ] _; it's best to not add this as a
240
+ inferred type ` anywhere else < issue-276 _>` _; it's best to not add this as a
240
241
special case.
241
242
242
243
* Using ``(Type, Ann1, Ann2, ...) `` instead of
@@ -253,40 +254,34 @@ This feature was left out to keep the design simple:
253
254
little benefit.
254
255
255
256
256
- References
257
- ----------
258
-
259
- .. [issue-600 ]
257
+ .. _issue-600 :
260
258
https://github.com/python/typing/issues/600
261
259
262
- .. [ python -ideas]
260
+ .. _ python -ideas:
263
261
https://mail.python.org/pipermail/python-ideas/2019-January/054908.html
264
262
265
- .. [struct-doc ]
266
- https://docs.python.org/3/library/struct.html#examples
267
-
268
- .. [mypy ]
263
+ .. _mypy :
269
264
http://www.mypy-lang.org/
270
265
271
- .. [ pyre ]
266
+ .. _ pyre :
272
267
https://pyre-check.org/
273
268
274
- .. [ pycharm ]
269
+ .. _ pycharm :
275
270
https://www.jetbrains.com/pycharm/
276
271
277
- .. [ pytype ]
272
+ .. _ pytype :
278
273
https://github.com/google/pytype
279
274
280
- .. [ mypy -plugin]
275
+ .. _ mypy -plugin:
281
276
https://github.com/python/mypy_extensions
282
277
283
- .. [ tagged -union]
278
+ .. _ tagged -union:
284
279
https://en.wikipedia.org/wiki/Tagged_union
285
280
286
- .. [ typed -dict]
281
+ .. _ typed -dict:
287
282
https://mypy.readthedocs.io/en/latest/more_types.html#typeddict
288
283
289
- .. [ issue -276]
284
+ .. _ issue -276:
290
285
https://github.com/python/typing/issues/276
291
286
292
287
Copyright
0 commit comments