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

Type Checking for Class Row Factory

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

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Esamina prima Issue #42 e PR #57, poiché la soluzione proposta è descritta lì. Poi ispeziona comdb2.dataclasses.class_row_factory e confronta l’esempio BaseRowFactoryClass con la problematica di type-checking indicata. Il lavoro è completato quando si conferma se il PR affronta completamente la validazione degli attributi delle dataclass e dell’output del database.

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

Descrizione

As described in Issue #42 there was a proposed solution for having a Class Row Factory. Alongside the conversations happened there, there was a concern regarding type checking for the attributes of the class and output returned by the database. There doesn't seem to be a way to enforce type checking hence an extra __post_init__ method would be required within the class to enforce type checking. This can be overlooked by a lot of developers and can lead to a lot of type mismatches.

Solution

Define a Base class that our dataclasses can inherit. The Base class can have all the required methods for the validation etc.

The updated use of it can be described it here. The solution has been implemented on the PR #57

        >>> from dataclasses import dataclass
        >>> from comdb2.dataclasses.class_row_factory import BaseRowFactoryClass
        ...
        >>> @dataclass
        >>> class ABC(BaseRowFactoryClass):
        >>>     x: int
        >>>     y: int
        
        ...
        >>> conn.row_factory = ClassRowFactory(ABC)
        >>> row = conn.cursor().execute("select 1 as x, 2 as y").fetchone()
        >>> print(row)
        <>
        >>> print(row.x)
Lingua principale
Python
Stelle
29
Fork
28
Merge medio
11h 25m
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 bloomberg/python-comdb2

Tutte le issue di bloomberg/python-comdb2

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.