python / python/mypy

Potential Cache Bug in Daemon Mode with Passed-in String Code

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

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

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

説明

Bug Report

I encountered a potential caching issue when using dmypy to type-check in-command code string. The issue arises when executing commands with dmypy run -- -c <code>. As shown below, the second command should not produce an error, as the assignment is correct (int to int). However, it seems like the daemon is caching the previous state incorrectly, leading to an error.

I understand that using dmypy in this manner is not typical, as it is primarily designed to be a long-running daemon process, which allows to perform type checking more efficiently by caching state. However, the documentation states that "You can use almost arbitrary mypy flags after --", which suggests that this usage should be supported. This might lead to misunderstandings or confusion about the expected behavior when using inline code execution with dmypy. Additionally, any tooling that leverages the -c option in dmypy for inline type checking will be impacted by this behavior, potentially causing issues in automated workflows and integrations.

To Reproduce, and Actual Behavior

$ dmypy run -- -c "a:str=1"
<string>:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")  [assignment]
Found 1 error in 1 file (checked 1 source file)

$ dmypy run -- -c "a:int=1"
<string>:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Expected Behavior

$ dmypy run -- -c "a:int=1"    # second time
Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 1.13.0
  • Python version used: 3.12.3

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

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

はじめの一歩

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

調査の方向性

まず、issue にある 2 つの dmypy run -- -c コマンドを mypy 1.13.0 で再現し、次に、渡された文字列コードの dmypy による処理と、そのキャッシュ状態を追跡します。2 番目のコマンドが 1 番目のコマンドの型エラーを保持したままではなく成功を報告し、連続したインラインチェックのリグレッションカバレッジが追加されていれば完了です。

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

評価

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

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

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