Repository: ermakov-oleg/serpyco-rs (language: python)

Issue:
Int Enum support
Now int enum in serializer.dump converted IntEnum to str value, instead of int

```python
from dataclasses import dataclass
from enum import IntEnum

import serpyco_rs


class TestEnum(IntEnum):
    one = 1
    two = 2


@dataclass(slots=True)
class Test:
    obj_type: TestEnum


serializer = serpyco_rs.Serializer(
    Test,
    camelcase_fields=True,
    omit_none=True,
)


data = {
  'objType': 1,
}
obj = serializer.load(data)
print(obj)
// Test(obj_type=<TestEnum.one: 1>)

data = serializer.dump(Test(obj_type=TestEnum.two))
print(data)
// {'objType': '2'}
// expected {'objType': 2}

```

Versions:
- python - 3.11.0
- serpyco-rs - 0.10.0
- OS - macos 13.3.1


Discussion / hints:

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index 4425ad9..2ae396a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -199,7 +199,7 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
 
 [[package]]
 name = "serpyco-rs"
-version = "0.10.0"
+version = "0.10.1"
 dependencies = [
  "atomic_refcell",
  "cfg-if",
diff --git a/Cargo.toml b/Cargo.toml
index fe03e56..e675e03 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "serpyco-rs"
-version = "0.10.0"
+version = "0.10.1"
 edition = "2021"
 homepage = "https://github.com/ermakov-oleg/serpyco-rs"
 repository = "https://github.com/ermakov-oleg/serpyco-rs"
diff --git a/src/serializer/encoders.rs b/src/serializer/encoders.rs
index f9f0db9..971e638 100644
--- a/src/serializer/encoders.rs
+++ b/src/serializer/encoders.rs
@@ -234,7 +234,7 @@ pub struct EnumEncoder {
 impl Encoder for EnumEncoder {
     #[inline]
     fn dump(&self, value: *mut PyObject) -> PyResult<*mut PyObject> {
-        obj_to_str(py_object_get_attr(value, unsafe { VALUE_STR })?)
+        py_object_get_attr(value, unsafe { VALUE_STR })
     }
 
     #[inline]


Test patch:
diff --git a/tests/json_schema/test_convert.py b/tests/json_schema/test_convert.py
index 2aa849b..9c2a5cc 100644
--- a/tests/json_schema/test_convert.py
+++ b/tests/json_schema/test_convert.py
@@ -73,11 +73,11 @@ class Data:
                         "e": {"maxLength": 5, "minLength": 1, "type": "string"},
                         "f": {"format": "uuid", "type": "string"},
                         "g": {
-                            "pattern": "^[0-9][0-9]:[0-9][0-9](:[0-9][0-9](\.[0-9]+)?)?$",
+                            "pattern": r"^[0-9][0-9]:[0-9][0-9](:[0-9][0-9](\.[0-9]+)?)?$",
                             "type": "string",
                         },
                         "h": {
-                            "pattern": "^[0-9]{4}-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9](\\.[0-9]+)?(([+-][0-9][0-9]:[0-9][0-9])|Z)?$",
+                            "pattern": r"^[0-9]{4}-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9](\.[0-9]+)?(([+-][0-9][0-9]:[0-9][0-9])|Z)?$",
                             "type": "string",
                         },
                         "i": {"enum": ["a"]},
diff --git a/tests/test_encoders.py b/tests/test_encoders.py
index 4e7c644..2d82691 100644
--- a/tests/test_encoders.py
+++ b/tests/test_encoders.py
@@ -3,12 +3,11 @@
 from dataclasses import dataclass
 from datetime import date, datetime, time, timedelta, timezone
 from decimal import Decimal
-from enum import Enum
+from enum import Enum, IntEnum
 from typing import Literal
 from zoneinfo import ZoneInfo
 
 import pytest
-from dateutil.tz import tzoffset
 from serpyco_rs import Serializer, ValidationError
 
 
@@ -209,3 +208,26 @@ class T:
     assert serializer.dump(T(foo=1)) == {"foo": 1}
     assert serializer.load({}) == T()
     assert serializer.load({"foo": 12}) == T(foo=12)
+
+
+def test_int_enum():
+    class Foo(IntEnum):
+        foo = 1
+        bar = 2
+
+    serializer = Serializer(Foo)
+    assert serializer.dump(Foo.foo) == 1
+    assert serializer.load(1) == Foo.foo
+
+
+@pytest.mark.skipif(sys.version_info < (3, 11), reason="StrEnum available after 3.11")
+def test_str_enum():
+    from enum import StrEnum
+
+    class Foo(StrEnum):
+        foo = "foo"
+        bar = "bar"
+
+    serializer = Serializer(Foo)
+    assert serializer.dump(Foo.foo) == "foo"
+    assert serializer.load("bar") == Foo.bar