Skip to content

false positive no-any-return from a typed function nested in an untyped function #20566

@tsteven4

Description

@tsteven4

Bug Report

If an inner typed function which returns something other than None is nested within an untyped function then an error is generated about returning Any from the inner function.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.13&flags=warn-return-any&gist=469f5edd5d720344bf088f4c1294ad6e

Expected Behavior

bug.py:7: note: Revealed type is "pathlib.Path"
bug.py:15: note: Revealed type is "pathlib.Path"
bug.py:26: note: Revealed type is "pathlib.Path"
Success: no issues found in 1 source file

Actual Behavior

main.py:7: note: Revealed type is "pathlib.Path"
main.py:15: note: Revealed type is "pathlib.Path"
main.py:26: note: Revealed type is "Any"
main.py:27: error: Returning Any from function declared to return "str" [no-any-return]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used:1.19.1
  • Mypy command-line flags: --warn-return-any
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.13

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions