Skip to content

Commit 6cd0de0

Browse files
committed
liniting
1 parent 4942a4a commit 6cd0de0

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

pydantic_extra_types/epoch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def __get_pydantic_json_schema__(
2121
def __get_pydantic_core_schema__(
2222
cls, source: type[Any], handler: Callable[[Any], CoreSchema]
2323
) -> core_schema.CoreSchema:
24-
def f(value, serializer):
24+
def f(value: Any, serializer: Callable[[datetime.datetime], float]) -> float:
2525
return serializer(value.timestamp())
26+
2627
return core_schema.with_info_after_validator_function(
27-
cls._validate, core_schema.float_schema(),
28-
serialization=core_schema.wrap_serializer_function_ser_schema(f, return_schema=core_schema.float_schema())
28+
cls._validate,
29+
core_schema.float_schema(),
30+
serialization=core_schema.wrap_serializer_function_ser_schema(f, return_schema=core_schema.float_schema()),
2931
)
3032

3133
@classmethod
32-
def _validate(cls, __input_value: Any, _: Any) -> "Epoch":
34+
def _validate(cls, __input_value: Any, _: Any) -> datetime.datetime:
3335
return EPOCH + datetime.timedelta(seconds=__input_value)
34-
35-

tests/test_epoch.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
from pydantic_extra_types.epoch import Epoch
66

7-
@pytest.mark.parametrize('type_',[(int,),(float,)], ids=["integer", "float"])
7+
8+
@pytest.mark.parametrize('type_', [(int,), (float,)], ids=['integer', 'float'])
89
def test_type(type_):
910
from pydantic import BaseModel
1011

@@ -13,25 +14,25 @@ class A(BaseModel):
1314

1415
now = datetime.datetime.now(tz=datetime.timezone.utc)
1516
ts = type_(now.timestamp())
16-
a = A.model_validate({"epoch":ts})
17+
a = A.model_validate({'epoch': ts})
1718
v = a.model_dump()
18-
assert v["epoch"] == ts
19+
assert v['epoch'] == ts
1920

2021
b = A.model_construct(epoch=now)
2122

2223
v = b.model_dump()
23-
assert v["epoch"] == ts
24+
assert v['epoch'] == ts
2425

2526
c = A.model_validate(dict(epoch=ts))
2627
v = c.model_dump()
27-
assert v["epoch"] == ts
28+
assert v['epoch'] == ts
2829

2930

3031
def test_schema():
3132
from pydantic import BaseModel
33+
3234
class A(BaseModel):
3335
dt: Epoch
3436

3537
v = A.model_json_schema()
36-
assert (dt:=v["properties"]["dt"])["type"] == "number" and dt["format"] == "date-time"
37-
38+
assert (dt := v['properties']['dt'])['type'] == 'number' and dt['format'] == 'date-time'

0 commit comments

Comments
 (0)