Skip to content

Commit

Permalink
Merge branch 'anna-money:main' into feature/generics
Browse files Browse the repository at this point in the history
  • Loading branch information
slawwan authored Nov 12, 2024
2 parents 9ca2430 + 5c05cb3 commit 395fd0b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion marshmallow_recipe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"get_validation_field_errors",
)

__version__ = "0.0.41"
__version__ = "0.0.43"

version = f"{__version__}, Python {sys.version}"

Expand Down
9 changes: 9 additions & 0 deletions marshmallow_recipe/bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class _SchemaTypeKey:

_T = TypeVar("_T")
_MARSHMALLOW_VERSION_MAJOR = int(m.__version__.split(".")[0])

_schema_types: dict[_SchemaTypeKey, type[m.Schema]] = {}


Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
9 changes: 3 additions & 6 deletions marshmallow_recipe/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"pythonVersion": "3.10",
"pythonVersion": "3.11",
"pythonPlatform": "All",
"stubPath": "",
"typeCheckingMode": "strict",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
Expand Down
21 changes: 21 additions & 0 deletions tests/test_order.py
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 395fd0b

Please sign in to comment.