diff --git a/CHANGELOG.md b/CHANGELOG.md index 7622c61..0059815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## v0.0.43(2024-11-11) + +* [Fix python_requires to be >=3.11](https://github.com/anna-money/marshmallow-recipe/commit/ab1eca29324569dbcc712f589078eee9980f9b10) +* [Switch to StrEnum](https://github.com/anna-money/marshmallow-recipe/commit/e732d5a6c96f3316f7d33d903f15680f83b63fbe) + + +## v0.0.42(2024-11-09) + +* [Preserve declaration order](https://github.com/anna-money/marshmallow-recipe/pull/164) + + ## v0.0.41(2024-11-01) * [Int enum support](https://github.com/anna-money/marshmallow-recipe/pull/161) diff --git a/marshmallow_recipe/__init__.py b/marshmallow_recipe/__init__.py index 3c95b2a..5072cab 100644 --- a/marshmallow_recipe/__init__.py +++ b/marshmallow_recipe/__init__.py @@ -103,7 +103,7 @@ "get_validation_field_errors", ) -__version__ = "0.0.41" +__version__ = "0.0.43" version = f"{__version__}, Python {sys.version}" diff --git a/marshmallow_recipe/bake.py b/marshmallow_recipe/bake.py index 148848e..5af9bc0 100644 --- a/marshmallow_recipe/bake.py +++ b/marshmallow_recipe/bake.py @@ -45,6 +45,7 @@ class _SchemaTypeKey: _T = TypeVar("_T") _MARSHMALLOW_VERSION_MAJOR = int(m.__version__.split(".")[0]) + _schema_types: dict[_SchemaTypeKey, type[m.Schema]] = {} @@ -289,6 +290,10 @@ class _Schema(m.Schema): class Meta: # type: ignore unknown = m.EXCLUDE # type: ignore + @property + def set_class(self) -> type: + return m.schema.OrderedSet # type: ignore + @m.post_dump def remove_none_values(self, data: dict[str, Any], **_: Any) -> dict[str, Any]: if none_value_handling == NoneValueHandling.IGNORE: @@ -312,6 +317,10 @@ def pre_load(self, data: dict[str, Any], **_: Any) -> Any: def _get_base_schema(cls: type, none_value_handling: NoneValueHandling) -> type[m.Schema]: class _Schema(m.Schema): # type: ignore + @property + def set_class(self) -> type: + return m.schema.OrderedSet # type: ignore + @m.post_dump # type: ignore def remove_none_values(self, data: dict[str, Any]) -> dict[str, Any]: if none_value_handling == NoneValueHandling.IGNORE: diff --git a/marshmallow_recipe/options.py b/marshmallow_recipe/options.py index 2393001..a4af062 100644 --- a/marshmallow_recipe/options.py +++ b/marshmallow_recipe/options.py @@ -8,12 +8,9 @@ _OPTIONS_KEY = "__marshmallow_recipe_options__" -class NoneValueHandling(str, enum.Enum): - IGNORE = "IGNORE" - INCLUDE = "INCLUDE" - - def __str__(self) -> str: - return self.value +class NoneValueHandling(enum.StrEnum): + IGNORE = enum.auto() + INCLUDE = enum.auto() @dataclasses.dataclass(kw_only=True, slots=True, frozen=True) diff --git a/pyrightconfig.json b/pyrightconfig.json index 2356a05..7f18237 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -1,5 +1,5 @@ { - "pythonVersion": "3.10", + "pythonVersion": "3.11", "pythonPlatform": "All", "stubPath": "", "typeCheckingMode": "strict", diff --git a/requirements-dev.txt b/requirements-dev.txt index aa66ed5..9340938 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,7 +2,7 @@ pytest==8.3.3 isort==5.13.2 flake8==7.1.1 black==24.10.0 -pyright==1.1.387 +pyright==1.1.388 marshmallow>=2,<4 setuptools diff --git a/setup.py b/setup.py index 75486b5..3d9ce88 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ def read_version(): long_description_content_type="text/markdown", platforms=["macOS", "POSIX", "Windows"], author="Yury Pliner", - python_requires=">=3.10", + python_requires=">=3.11", project_urls={}, url="https://github.com/Pliner/marshmallow-recipe", author_email="yury.pliner@gmail.com", diff --git a/tests/test_order.py b/tests/test_order.py new file mode 100644 index 0000000..dd5b500 --- /dev/null +++ b/tests/test_order.py @@ -0,0 +1,21 @@ +import dataclasses + +import marshmallow_recipe as mr + + +def test_order_1(): + @dataclasses.dataclass + class A: + a: int + b: int + + assert [name for name in mr.dump(A(a=1, b=2))] == ["a", "b"] + + +def test_order_2(): + @dataclasses.dataclass + class A: + b: int + a: int + + assert [name for name in mr.dump(A(b=1, a=2))] == ["b", "a"]