google / google/python-spanner-orm

Re-write Model to use dataclasses.

未關閉
#97 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
41
分支
17
PR 合併指標
30 天內沒有已合併 PR

描述

`Model` currently uses a metaclass (which is disallowed by the style guide for good reasons) and `Field`s which make type checking tricky. (The class attribute is of type `Field`, but the instance attribute with the same name is of type `str`, `int`, or whatever that specific field stores.) I think most of this could be solved by switching to something based on `dataclasses`. E.g., in Python 3.9+:

```python
@dataclasses.dataclass
class Foo(spanner_orm.Model):
foo: Annotated[int, spanner_orm.primary_key]
```

Or in older versions of Python:
```python
@dataclasses.dataclass
class Foo(spanner_orm.Model):
foo: int = dataclasses.field(metadata={spanner_orm.PRIMARY_KEY: True})
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。