Docstring says t.Tuple is supported, but typing.Tuple raises AttributeError

Aperta Adatta ai principianti
#53 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
88/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

Inizia dal docstring di Env in envier/env.py, righe 232-233, dove t.Tuple è elencato insieme a list e set. Leggi EnvVariable._cast (righe 78-87) e _check_type (righe 28-32) per confermare che l'alias nudo typing.Tuple non ha __args__. La correzione più semplice è cambiare il docstring in tuple; in alternativa, normalizza typing.Tuple/List/Set ai loro tipi di origine. Esegui i test delle collezioni esistenti e aggiungi un caso typing.Tuple se normalizzi.

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

Descrizione

The Env docstring says t.Tuple is supported as a collection type, but declaring a variable with typing.Tuple raises AttributeError when the value is read. The builtin tuple works.

Environment: envier 0.6.1, Python 3.12

Reproduction

import json
import typing
from envier import Env

try:
    class C(Env):
        x = Env.var(typing.Tuple, "x")
    print(json.dumps(C({"X": "a,b"}).x))
except Exception as e:
    print(json.dumps(type(e).__name__))

Actual output

"AttributeError"

Expected output

["a", "b"]

From the Env class docstring:

There is also basic support for collections. An item of type list, t.Tuple or set will be parsed using , as item separator.

https://github.com/DataDog/envier/blob/a8ee033fd2581be09c0d61eb6b8343f12c8f08e9/envier/env.py#L232-L233

Likely cause: EnvVariable._cast only handles _type in (list, tuple, set), so typing.Tuple falls through to _check_type, which reads _type.__args__; the bare typing.Tuple alias has no __args__:
https://github.com/DataDog/envier/blob/a8ee033fd2581be09c0d61eb6b8343f12c8f08e9/envier/env.py#L28-L32
https://github.com/DataDog/envier/blob/a8ee033fd2581be09c0d61eb6b8343f12c8f08e9/envier/env.py#L78-L87

Since the same sentence lists the builtins list and set and the tests use builtin tuple, the simplest fix may be to change t.Tuple to tuple in the docstring; alternatively typing.Tuple (and typing.List/typing.Set) could be normalized to their origin types.

Found while testing the library with an automated exploration tool; the reproduction above was re-run on 0.6.1 before filing.

Lingua principale
Python
Stelle
9
Fork
2
Merge medio
7h 22m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 DataDog/envier

Tutte le issue di DataDog/envier

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.