python / python/mypy

Incorrect precision calculation for TypedDict classes.

Aperta
#12,512 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-typed-dict
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

Descrizione

Bug Report

When defining a TypedDict class as in the example below, the lines defining the members of the dict are considered to be imprecise by the reports.

To Reproduce

# Code with imprecise lines
from typing import TypedDict

class UserDict(TypedDict):
  user_id: int  # Marked imprecise
  email: str  # Marked imprecise

user:UserDict = { 'user_id': 1, 'email': 'you@somewhere.com' }

The functionally equivalent alternative way shows all lines as precise:

# All lines are marked precise
from typing import TypedDict

UserDict = TypedDict('UserDict', {'user_id': int, 'email': str})

user:UserDict = { 'user_id': 1, 'email': 'you@somewhere.com' }

Expected Behavior

The member definitions in a TypedDict class should be marked precise.

Actual Behavior

Only 5 / 7 lines of code are considered precise with the user_id: int and email: str lines being marked imprecise. In the HTML report those lines have the title Any Types on this line: Error (x1).

Your Environment

  • Python 3.10.3
  • mypy 0.942
  • Clean venv, run with `mypy --html-report report --txt-report . .``
  • Ubuntu 20.04.4

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 eseguendo il comando mypy indicato sulla riproduzione di TypedDict e confronta i report HTML e testuale per la sintassi di classe con la forma funzionale. Il lavoro è completato quando le righe dei membri user_id e email sono contrassegnate come precise invece di riportare tipi Any.

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

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 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.