google / google/python-spanner-orm

Re-write Model to use dataclasses.

Offen
#97 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
41
Forks
17
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

`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})
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.