Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions docs/source/error_code_list2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ Check that function does not return Any value [no-any-return]
-------------------------------------------------------------

If you use :option:`--warn-return-any <mypy --warn-return-any>`, mypy generates an error if you return a
value with an ``Any`` type in a function that is annotated to return a
non-``Any`` value.
value with a plain ``Any`` type in a function that is annotated to return a
non-``Any`` value. You can use this to enforce better boundaries around unsafe/dynamic code

Example:

Expand All @@ -207,9 +207,15 @@ Example:
def fields(s):
return s.split(',')

def first_field(x: str) -> str:
# Error: Returning Any from function declared to return "str" [no-any-return]
return fields(x)[0]
def reversed_fields_bad(x: str) -> list[str]:
# Error: Returning Any from function declared to return "list[str]" [no-any-return]
return fields(x)[::-1]

def reversed_fields_ok(x: str) -> list[str]:
x_fields = fields(x)
assert isinstance(x_fields, list)
# OK, we can at least guarantee return is list[Any]
return x_fields[::-1]

.. _code-no-any-unimported:

Expand Down
Loading