Skip to content

Commit 5c4aea3

Browse files
authored
error_code_list2.rst: typo + edit (#11052)
1 parent 26673be commit 5c4aea3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/source/error_code_list2.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,26 @@ since unless implemented by a sub-type, the expression will always evaluate to t
234234
...
235235
236236
237-
This check might falsely imply an error. For example, ``typing.Iterable`` does not implement
237+
This check might falsely imply an error. For example, ``Iterable`` does not implement
238238
``__len__`` and so this code will be flagged:
239239

240240
.. code-block:: python
241241
242242
# mypy: enable-error-code truthy-bool
243+
from typing import Iterable
243244
244-
def transform(items: Iterable[int]) -> List[int]:
245-
# Error: "items" has type "typing.Iterable[int]" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
245+
def transform(items: Iterable[int]) -> Iterable[int]:
246+
# Error: "items" has type "Iterable[int]" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
246247
if not items:
247248
return [42]
248249
return [x + 1 for x in items]
249250
250251
251252
252-
If called as ``transform((int(s) for s in []))``, this function would not return ``[42]]`` unlike what the author
253+
If called as ``transform((int(s) for s in []))``, this function would not return ``[42]`` unlike what the author
253254
might have intended. Of course it's possible that ``transform`` is only passed ``list`` objects, and so there is
254-
no error in practice. In such case, it might be prudent to annotate ``items: typing.Sequence[int]``.
255+
no error in practice. In such case, it might be prudent to annotate ``items: Sequence[int]``.
255256

256-
This is similar in concept to ensuring that an expression's type implements an expected interface (e.g. ``typing.Sized``),
257+
This is similar in concept to ensuring that an expression's type implements an expected interface (e.g. ``Sized``),
257258
except that attempting to invoke an undefined method (e.g. ``__len__``) results in an error,
258259
while attempting to evaluate an object in boolean context without a concrete implementation results in a truthy value.

0 commit comments

Comments
 (0)