python / python/mypy

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

Aperta
#18,326 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-daemon
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo i due comandi dmypy run -- -c dell’issue con mypy 1.13.0, quindi traccia la gestione da parte di dmypy del codice stringa passato e dello stato della sua cache. Il lavoro è completato quando il secondo comando segnala il successo invece di conservare l’errore di tipo del primo comando, con copertura di regressione per i controlli inline sequenziali.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.