Skip to content
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

Remove leftover Pydantic v1 handling #642

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions python_on_whales/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import subprocess
import sys
from datetime import datetime, timedelta
from importlib.metadata import version
from pathlib import Path
from queue import Queue
from subprocess import PIPE, Popen
Expand Down Expand Up @@ -36,14 +35,10 @@
)

PROJECT_ROOT = Path(__file__).parents[1]
PYDANTIC_V2 = version("pydantic").startswith("2.")


def custom_parse_object_as(type_, obj: Any):
if PYDANTIC_V2:
return pydantic.TypeAdapter(type_).validate_python(obj)
else:
return pydantic.parse_obj_as(type_, obj)
return pydantic.TypeAdapter(type_).validate_python(obj)


def title_if_necessary(string: str):
Expand Down Expand Up @@ -93,16 +88,10 @@ def to_docker_camel(string):


class DockerCamelModel(pydantic.BaseModel):
if PYDANTIC_V2:
model_config = pydantic.ConfigDict(
populate_by_name=True,
alias_generator=to_docker_camel,
)
else:

class Config:
alias_generator = to_docker_camel
allow_population_by_field_name = True
model_config = pydantic.ConfigDict(
populate_by_name=True,
alias_generator=to_docker_camel,
)


@overload
Expand Down
Loading