bloomberg / bloomberg/python-comdb2
Type Checking for Class Row Factory
- Linguagem predominante
- Python
- Estrelas
- 29
- Forks
- 28
- Merge médio
- 11h 25min
- PRs com merge (30d)
- 2
Descrição
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)
```
Guia de contribuição
Direção de pesquisa
Revise primeiro o Issue #42 e o PR #57, pois a solução proposta está descrita neles. Em seguida, inspecione comdb2.dataclasses.class_row_factory e compare o exemplo BaseRowFactoryClass com a preocupação de verificação de tipos mencionada. O trabalho estará concluído ao confirmar se o PR aborda totalmente a validação dos atributos de dataclass e da saída do banco de dados.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- databases
- Tipo de issue
- Funcionalidade
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 20/100