AnswerDotAI / AnswerDotAI/fastsql
Extend dataclass
- Dominant language
- Jupyter Notebook
- Stars
- 69
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
If you'd like to extend the `@dataclass` decorator to allow to add more settings to the table class itself, for example move the "pk='name'" in the class decorator, you can do that by using `dataclass_transform` imported from the `typing` module, for instance
```py
from dataclasses import dataclass
from typing import dataclass_transform
@dataclass_transform()
def useTable(pk: str):
def decorator(cls):
cls = dataclass(cls)
cls.__pk__ = pk
return cls
return decorator
@useTable("table_1")
class Example:
name: str
age: int
ex1 = Example("John", 30)
print(ex1)
# Output: Example(name='John', age=30)
```
Plus ex1 has all the type hints in the editor as the normal dataclass does.
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue names no files or tests; first locate the current table and dataclass decorator entry points and read how primary keys are configured. Compare that behavior with the proposed useTable example, then verify that the decorator accepts table settings while retaining dataclass construction and editor type hints.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100