Use pydantic v2

main
Estelle Poulin 2 months ago
parent 6ef0014245
commit e851113ffd

@ -0,0 +1,10 @@
[flake8]
# https://lintlyci.github.io/Flake8Rules/
# E231 missing whitespace after ','
# E266 Too many leading '#' for block comment
# E501 Line too long (82 > 79 characters)
# W503 Line break occurred before a binary operator <- This one is flipping to the reverse as best-practice, which is how Black currently formats
# W605 Invalid escape sequence 'x'
ignore = E203, E231, E266, E501, W503, W605, E704
max-line-length = 100
exclude = .git, .venv, __pycache__, docs, gitlab-ci-includes

@ -1,2 +1,3 @@
aiohttp==3.8.4
pydantic==1.10.2
aiohttp>=3.8.4
pydantic>=2.11.5
pydantic-core>=2.33.2

@ -1 +1 @@
__version__ = "0.0.3"
__version__ = "0.0.6"

@ -5,7 +5,7 @@ import textwrap
from typing import Optional
import aiohttp
from pydantic import validate_arguments
from pydantic import validate_call
from rtex.constants import DEFAULT_API_HOST, FORMAT_MIME
from rtex.exceptions import RtexError, YouNeedToUseAContextManager
@ -73,7 +73,7 @@ class AsyncRtexClient:
)
)
@validate_arguments
@validate_call
async def create_render(
self,
code: str,
@ -99,16 +99,16 @@ class AsyncRtexClient:
res = await self.session.post(
"/api/v2",
headers={"Accept": "application/json"},
data=request_body.json(
data=request_body.model_dump_json(
exclude_defaults=True,
exclude_none=True,
exclude_unset=True,
),
)
return CreateLaTeXDocumentResponse.parse_obj(await res.json()).__root__
return CreateLaTeXDocumentResponse.model_validate(await res.json()).root
@validate_arguments(config={"arbitrary_types_allowed": True})
@validate_call(config={"arbitrary_types_allowed": True})
async def save_render(
self,
filename: str,
@ -127,7 +127,7 @@ class AsyncRtexClient:
async for chunk, _ in res.content.iter_chunks():
output_fd.write(chunk)
@validate_arguments
@validate_call
async def get_render(
self,
filename: str,
@ -139,7 +139,7 @@ class AsyncRtexClient:
return buf
@validate_arguments
@validate_call
async def render_math(
self,
code: str,

@ -1,6 +1,6 @@
from typing import Annotated, Literal, Optional, Union
from pydantic import BaseModel, Field, conint
from pydantic import BaseModel, Field, RootModel, conint
RenderFormat = Literal["png", "jpg", "pdf"]
RenderQuality = Annotated[int, conint(gt=0, le=100)]
@ -26,8 +26,8 @@ class CreateLaTeXDocumentErrorResponse(BaseModel):
description: str
class CreateLaTeXDocumentResponse(BaseModel):
__root__: Union[
class CreateLaTeXDocumentResponse(RootModel):
root: Union[
CreateLaTeXDocumentSuccessResponse,
CreateLaTeXDocumentErrorResponse,
] = Field(discriminator="status")

Loading…
Cancel
Save