-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pydantic v2 support #304
base: master
Are you sure you want to change the base?
Pydantic v2 support #304
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,27 @@ | |
from uplink.clients import io | ||
|
||
from . import test_retry | ||
import sys | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_retry_with_asyncio(mock_client, mock_response): | ||
import asyncio | ||
# Check the Python version and define coroutine accordingly | ||
if sys.version_info >= (3, 5): | ||
# For Python 3.5 and newer | ||
async def coroutine(): | ||
return mock_response | ||
elif (3, 3) <= sys.version_info < (3, 5): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be safe to drop this. I don't believe we officially support Python versions below 3.5 |
||
# For Python 3.3 and 3.4 | ||
import asyncio | ||
@asyncio.coroutine | ||
def coroutine(): | ||
yield | ||
return mock_response | ||
else: | ||
# Not applicable for Python 2 | ||
return | ||
|
||
@asyncio.coroutine | ||
def coroutine(): | ||
return mock_response | ||
|
||
# Setup | ||
mock_response.with_json({"id": 123, "name": "prkumar"}) | ||
mock_client.with_side_effect([Exception, coroutine()]) | ||
mock_client.with_io(io.AsyncioStrategy()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
|
||
def _encode_pydantic(obj): | ||
from pydantic.json import pydantic_encoder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that here is better to auto-detect the version of pydantic that is installed and import the correct function so we keep backward compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, good point. Pydantic claims they will stop supporting V1 when V3 is released (somewhere this year), so I am not sure if V1 support gonna be needed. |
||
from pydantic_core import to_jsonable_python | ||
|
||
# json atoms | ||
if isinstance(obj, (str, int, float, bool)) or obj is None: | ||
|
@@ -22,7 +22,7 @@ def _encode_pydantic(obj): | |
return [_encode_pydantic(i) for i in obj] | ||
|
||
# pydantic types | ||
return _encode_pydantic(pydantic_encoder(obj)) | ||
return _encode_pydantic(to_jsonable_python(obj)) | ||
|
||
|
||
class _PydanticRequestBody(Converter): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking: I would expect this to throw a SyntaxError for Python 2.7. But, we are way beyond EOL now, and should drop 2.7 support IMO.