python / python/mypy

mypy RecursionError analyzing pint.facets.plain.quantity.PlainQuantity

オープン
#21,985 コメント 3 件 リアクション 2 件 担当者 0 名 GitHub で見る

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

crash topic-recursive-types
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Crash Report

mypy crashes with RecursionError while analyzing pint (since pint==0.26.1). Reproduced with compiled and non-compiled mypy.

Traceback

... skipping approx 50000 lines ...
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 560, in visit_instance
    return self.query_types(t.args)
           ~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in query_types
    return any(t.accept(self) for t in types)
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in <genexpr>
    return any(t.accept(self) for t in types)
               ~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/types.py", line 1684, in accept
    return visitor.visit_instance(self)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 560, in visit_instance
    return self.query_types(t.args)
           ~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in query_types
    return any(t.accept(self) for t in types)
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in <genexpr>
    return any(t.accept(self) for t in types)
               ~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/types.py", line 1684, in accept
    return visitor.visit_instance(self)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 560, in visit_instance
    return self.query_types(t.args)
           ~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in query_types
    return any(t.accept(self) for t in types)
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/type_visitor.py", line 628, in <genexpr>
    return any(t.accept(self) for t in types)
               ~~~~~~~~^^^^^^
  File "/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/mypy/types.py", line 1684, in accept
    return visitor.visit_instance(self)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
RecursionError: maximum recursion depth exceeded
/home/quentin/dev/QSA/pint_0.x/.venv/lib/python3.13/site-packages/pint/facets/numpy/quantity.py:63: note: use --pdb to drop into pdb
RecursionError: maximum recursion depth exceeded

To Reproduce

I narrowed down the issue to this single import of pint.facets.plain.quantity.PlainQuantity.
Run mypy on a file with this content:

from pint.facets.plain.quantity import PlainQuantity

Your Environment

Issue appears since version 0.26 of pint when they introduced massive type annotations for PlainQuantity. See https://github.com/hgrecco/pint/pull/2302 and https://github.com/hgrecco/pint/pull/2303

  • Mypy version used: 2.3.1 and 1.9.1
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.13.12
  • Operating system and version: Fedora 43 in WSL2

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

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

はじめの一歩

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

調査の方向性

まず、pint.facets.plain.quantity.PlainQuantityをimportするファイルで、mypyによるクラッシュを再現します。言及されているパス type_visitor.py と types.py を通る再帰を追跡し、その後、同じimportの解析がRecursionErrorなしで完了することを確認します。

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

評価

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

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

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