false positive no-any-return from a typed function nested in an untyped function
Nobody has claimed this yet.
- 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
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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