@@ -200,7 +200,7 @@ mypy generates an error if it thinks that an expression is redundant.
200200
201201.. code-block :: python
202202
203- # mypy: enable-error-code redundant-expr
203+ # Use " mypy -- enable-error-code redundant-expr ..."
204204
205205 def example (x : int ) -> None :
206206 # Error: Left operand of "and" is always true [redundant-expr]
@@ -222,7 +222,7 @@ since unless implemented by a sub-type, the expression will always evaluate to t
222222
223223.. code-block :: python
224224
225- # mypy: enable-error-code truthy-bool
225+ # Use " mypy -- enable-error-code truthy-bool ..."
226226
227227 class Foo :
228228 pass
@@ -237,7 +237,8 @@ This check might falsely imply an error. For example, ``Iterable`` does not impl
237237
238238.. code-block :: python
239239
240- # mypy: enable-error-code truthy-bool
240+ # Use "mypy -enable-error-code truthy-bool ..."
241+
241242 from typing import Iterable
242243
243244 def transform (items : Iterable[int ]) -> Iterable[int ]:
@@ -270,7 +271,7 @@ Example:
270271
271272.. code-block :: python
272273
273- # mypy: enable-error-code ignore-without-code
274+ # Use " mypy -- enable-error-code ignore-without-code ..."
274275
275276 class Foo :
276277 def __init__ (self , name : str ) -> None :
@@ -288,3 +289,32 @@ Example:
288289 # This line warns correctly about the typo in the attribute name
289290 # Error: "Foo" has no attribute "nme"; maybe "name"?
290291 f.nme = 42 # type: ignore [ assignment ]
292+
293+ Check that awaitable return value is used [unused-awaitable]
294+ ------------------------------------------------------------
295+
296+ If you use :option: `--enable-error-code unused-awaitable <mypy --enable-error-code> `,
297+ mypy generates an error if you don't use a returned value that defines ``__await__ ``.
298+
299+ Example:
300+
301+ .. code-block :: python
302+
303+ # Use "mypy --enable-error-code unused-awaitable ..."
304+
305+ import asyncio
306+
307+ async def f () -> int : ...
308+
309+ async def g () -> None :
310+ # Error: Value of type "Task[int]" must be used
311+ # Are you missing an await?
312+ asyncio.create_task(f())
313+
314+ You can assign the value to a temporary, otherwise unused to variable to
315+ silence the error:
316+
317+ .. code-block :: python
318+
319+ async def g () -> None :
320+ _ = asyncio.create_task(f()) # No error
0 commit comments