python / python/mypy

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

Open
#20,566 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked mypy-play reproduction using Python 3.13 and --warn-return-any, then trace how mypy handles a typed inner function nested in an untyped function. Done means the inner function retains its inferred pathlib.Path return type and the reproduction reports no erroneous no-any-return error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.