GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Improve docs for no-any-return error code (#22070) · python/mypy@25d86c6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/source
    • error_code_list2.rst
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/source/error_code_list2.rst‎

Copy file name to clipboardExpand all lines: docs/source/error_code_list2.rst
+11-5Lines changed: 11 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ Check that function does not return Any value [no-any-return]
195195
-------------------------------------------------------------
196196

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

201201
Example:
202202

@@ -207,9 +207,15 @@ Example:
207207
def fields(s):
208208
return s.split(',')
209209
210-
def first_field(x: str) -> str:
211-
# Error: Returning Any from function declared to return "str" [no-any-return]
212-
return fields(x)[0]
210+
def reversed_fields_bad(x: str) -> list[str]:
211+
# Error: Returning Any from function declared to return "list[str]" [no-any-return]
212+
return fields(x)[::-1]
213+
214+
def reversed_fields_ok(x: str) -> list[str]:
215+
x_fields = fields(x)
216+
assert isinstance(x_fields, list)
217+
# OK, we can at least guarantee return is list[Any]
218+
return x_fields[::-1]
213219
214220
.. _code-no-any-unimported:
215221

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.