Skip to content

Commit 7400cf6

Browse files
committed
Update project to version 0.8.0 and add EmptyResponse model
This update bumps the project version from 0.7.1 to 0.8.0, reflected in both pyproject.toml and __init__.py. It also introduces a new model, EmptyResponse, which provides a placeholder response class when a response model is not provided. This improves handling of cases where a response model is None by returning an instance of EmptyResponse instead of raising a ValueError, enhancing error management. Additionally, the version constraint of pydantic has been adjusted to be less than 2, ensuring compatibility.
1 parent 7cb6694 commit 7400cf6

File tree

8 files changed

+812
-932
lines changed

8 files changed

+812
-932
lines changed

poetry.lock

Lines changed: 762 additions & 871 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pydantic_aiohttp/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
__version__ = '0.7.1'
1+
__version__ = '0.8.0'
2+
__author__ = "pylakey <[email protected]>"
23

34
from . import encoders
45
from . import utils

pydantic_aiohttp/client.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import logging
2-
from typing import (
3-
Any,
4-
Optional,
5-
Type,
6-
Union,
7-
)
2+
from typing import Any
3+
from typing import Optional
4+
from typing import Type
5+
from typing import Union
86

97
import aiohttp
108
import pydantic
@@ -13,30 +11,22 @@
1311
from ujson import JSONDecodeError
1412

1513
from .encoders import url_compatible_encoder
16-
from .errors import (
17-
HTTPError,
18-
ResponseParseError,
19-
errors_classes,
20-
)
21-
from .responses import (
22-
PydanticModelResponseClass,
23-
ResponseClass,
24-
StreamResponseClass,
25-
)
26-
from .types import (
27-
Body,
28-
Cookies,
29-
ErrorResponseModels,
30-
Headers,
31-
Params,
32-
ResponseType,
33-
)
34-
from .utils import (
35-
DEFAULT_DOWNLOAD_CHUNK_SIZE,
36-
json_serialize,
37-
model_to_dict,
38-
read_file_by_chunk,
39-
)
14+
from .errors import HTTPError
15+
from .errors import ResponseParseError
16+
from .errors import errors_classes
17+
from .responses import PydanticModelResponseClass
18+
from .responses import ResponseClass
19+
from .responses import StreamResponseClass
20+
from .types import Body
21+
from .types import Cookies
22+
from .types import ErrorResponseModels
23+
from .types import Headers
24+
from .types import Params
25+
from .types import ResponseType
26+
from .utils import DEFAULT_DOWNLOAD_CHUNK_SIZE
27+
from .utils import json_serialize
28+
from .utils import model_to_dict
29+
from .utils import read_file_by_chunk
4030

4131

4232
class Client:

pydantic_aiohttp/encoders.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
from enum import Enum
66
from pathlib import PurePath
77
from types import GeneratorType
8-
from typing import (
9-
Any,
10-
Callable,
11-
Dict,
12-
List,
13-
Optional,
14-
Set,
15-
Tuple,
16-
Union,
17-
)
8+
from typing import Any
9+
from typing import Callable
10+
from typing import Dict
11+
from typing import List
12+
from typing import Optional
13+
from typing import Set
14+
from typing import Tuple
15+
from typing import Union
1816

1917
from pydantic import BaseModel
2018
# noinspection PyProtectedMember

pydantic_aiohttp/responses.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import abc
22
import logging
3-
from typing import (
4-
Generic,
5-
Optional,
6-
Type,
7-
TypeVar,
8-
Union,
9-
)
3+
from typing import Generic
4+
from typing import Optional
5+
from typing import Type
6+
from typing import TypeVar
7+
from typing import Union
108

119
import aiofiles
1210
import aiohttp.web_response
1311
import pydantic
1412
import ujson
1513
from aiohttp.typedefs import PathLike
1614

15+
from .types import EmptyResponse
1716
from .utils import DEFAULT_DOWNLOAD_CHUNK_SIZE
1817

1918
ResponseContentType = TypeVar('ResponseContentType')
@@ -54,7 +53,8 @@ async def parse(self, *args, **kwargs) -> Optional[ResponseContentType]:
5453
class PydanticModelResponseClass(ResponseClass[PydanticModel]):
5554
async def parse(self, *args, response_model: Type[PydanticModel], **kwargs) -> PydanticModel:
5655
if response_model is None:
57-
raise ValueError('response_model could not be None. If you need bare dict use JSONResponseClass instead')
56+
return EmptyResponse()
57+
# raise ValueError('response_model could not be None. If you need bare dict use JSONResponseClass instead')
5858

5959
response_json = await self.aiohttp_response.json(
6060
encoding=self.charset,

pydantic_aiohttp/types.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from typing import (
2-
Any,
3-
Type,
4-
TypeVar,
5-
Union,
6-
)
1+
from typing import Any
2+
from typing import Type
3+
from typing import TypeVar
4+
from typing import Union
75

86
import pydantic
97

@@ -16,3 +14,7 @@
1614
ErrorResponseModels = dict[int, Type[pydantic.BaseModel]]
1715

1816
ResponseType = TypeVar('ResponseType')
17+
18+
19+
class EmptyResponse(pydantic.BaseModel):
20+
pass

pydantic_aiohttp/utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import typing
22
from os import PathLike
3-
from typing import (
4-
Optional,
5-
Union,
6-
)
3+
from typing import Optional
4+
from typing import Union
75

86
import aiofiles
97
import pydantic

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pydantic_aiohttp"
3-
version = "0.7.1"
3+
version = "0.8.0"
44
description = "Simple HTTP Client based on aiohttp with integration of pydantic"
55
authors = ["pylakey <[email protected]>"]
66
license = "MIT"
@@ -26,7 +26,7 @@ classifiers = [
2626
python = "^3.9"
2727
aiofiles = "^23.0.0"
2828
aiohttp = { extras = ["speedups"], version = "^3.8.1" }
29-
pydantic = "^1.10.4"
29+
pydantic = "^1.10.4,<2"
3030
ujson = "^5.7.0"
3131

3232
[tool.poetry.dev-dependencies]

0 commit comments

Comments
 (0)