From 99b97a7abbf9f195dbd2726f3a1aeb737a1f4aff Mon Sep 17 00:00:00 2001 From: George Bocharov Date: Thu, 18 Jan 2024 06:15:46 +0000 Subject: [PATCH] 1.0.0 release; added type hints for base model --- .github/workflows/test.yml | 4 ++-- .gitignore | 3 ++- pyproject.toml | 2 +- src/drf_pydantic/base_model.py | 4 +++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 62a1020..86b35c5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - name: Checkout uses: actions/checkout@v3 @@ -50,7 +50,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - name: Checkout uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index b94d518..03bfd0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ # Dev .vscode .venv +.devcontainer # Python -*.py[co] +*.py[cod] # Dev artifacts .coverage diff --git a/pyproject.toml b/pyproject.toml index 0b71038..da14842 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "drf-pydantic" -version = "0.5.0" +version = "1.0.0" description = "Use pydantic with the Django REST framework" license = "MIT" authors = ["George Bocharov "] diff --git a/src/drf_pydantic/base_model.py b/src/drf_pydantic/base_model.py index 15c20b9..4b1dddb 100644 --- a/src/drf_pydantic/base_model.py +++ b/src/drf_pydantic/base_model.py @@ -3,10 +3,12 @@ import pydantic from rest_framework import serializers +from typing_extensions import dataclass_transform from drf_pydantic.parse import create_serializer_from_model +@dataclass_transform(kw_only_default=True, field_specifiers=(pydantic.Field,)) class ModelMetaclass(pydantic.main.ModelMetaclass, type): def __new__(mcs, name, bases, namespace, **kwargs): cls = super().__new__(mcs, name, bases, namespace, **kwargs) @@ -17,4 +19,4 @@ def __new__(mcs, name, bases, namespace, **kwargs): class BaseModel(pydantic.BaseModel, metaclass=ModelMetaclass): if typing.TYPE_CHECKING: # populated by the metaclass, defined here to help IDEs only - drf_serializer: type[serializers.Serializer] + drf_serializer: typing.ClassVar[type[serializers.Serializer]]