Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

traitlets Dict with per_key_traits should be more specific in a TraitError

Aperta
#920 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia riproducendo l’esempio di Dict(per_key_traits) annidato dell’issue e segui il punto di ingresso della validazione di Dict per per_key_traits. La modifica è completa quando TraitError identifica la chiave errata o il percorso della chiave annidata e segnala chiaramente il valore effettivamente non valido; aggiungi una copertura di regressione per il caso mostrato se la struttura di test esistente lo consente.

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

Descrizione

I'm using traitlets version 5.14.3 and Python 3.12.3...

  • The error raised by Dict() with per_key_traits should specify the offending key name in the error.
  • The error raised by Dict() with per_key_traits doesn't handle nested dicts well

Example:

from traitlets import HasTraits, Dict, Unicode

class Foo(HasTraits):
    bar = Dict(per_key_traits={"this": Unicode(), "that": Dict(per_key_traits={"that": Unicode()})})

foo = Foo()
# key that should be a Dict()...
foo.bar = {"this": "valid", "that": False}

The error raised is:

traitlets.traitlets.TraitError: Values of the 'bar' trait of a Foo instance must be a dict, but a value of False <class 'bool'> was specified.

It would be better if it specified the offending chain of keys in the error... Example:

traitlets.traitlets.TraitError: Value of bar['that'] for a Foo instance must be a dict, but the specified value at bar['that'] was False <class 'bool'>.
Lingua principale
Python
Stelle
653
Fork
217
Merge medio
2g 21h
PR unite (30g)
2

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.

Altre issue di ipython/traitlets

Tutte le issue di ipython/traitlets

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.