Skip to content

Commit

Permalink
🐛 Fix: Add wrapper to prep data for JSON encoding (#22)
Browse files Browse the repository at this point in the history
closes #21
  • Loading branch information
dosisod authored Mar 21, 2023
1 parent bc1eb96 commit 8d9a7b1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions githubkit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)

import httpx
from pydantic.json import pydantic_encoder

from .response import Response
from .config import Config, get_config
Expand Down Expand Up @@ -237,7 +238,7 @@ def _request(
content=content,
data=data,
files=files,
json=json,
json=self._convert(json),
headers=headers,
cookies=cookies,
)
Expand Down Expand Up @@ -269,7 +270,7 @@ async def _arequest(
content=content,
data=data,
files=files,
json=json,
json=self._convert(json),
headers=headers,
cookies=cookies,
)
Expand Down Expand Up @@ -298,6 +299,18 @@ def _check(
raise RequestFailed(rep)
return Response(response, response_model)

def _convert(self, obj: Any) -> Any:
if isinstance(obj, dict):
return {k: self._convert(v) for k, v in obj.items()}

if isinstance(obj, (list, tuple)):
return [self._convert(item) for item in obj]

if obj is None or isinstance(obj, (int, float, str, bool)):
return obj

return pydantic_encoder(obj)

# sync request and check
def request(
self,
Expand Down

0 comments on commit 8d9a7b1

Please sign in to comment.