python / python/mypy

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

オープン
#20,566 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされている mypy-play の再現を Python 3.13 と --warn-return-any を使って開始し、その後、型付けされた内部関数が型付けされていない関数内にネストされている場合に mypy がどのように処理するかを追跡します。内部関数が推論された pathlib.Path の戻り値型を保持し、再現で誤った no-any-return エラーが報告されなければ完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。