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

Update to pydantic 2.0 #459

Merged
merged 4 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: check-ast

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
language_version: python3
Expand Down
8 changes: 1 addition & 7 deletions conda_lock/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from pydantic import BaseModel


class StrictModel(BaseModel):
class StrictModel(BaseModel, extra="forbid"):
"""A Pydantic BaseModel forbidding extra fields and encoding frozensets as lists"""
mariusvniekerk marked this conversation as resolved.
Show resolved Hide resolved

class Config:
extra = "forbid"
json_encoders = {
frozenset: list,
}
7 changes: 3 additions & 4 deletions conda_lock/models/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from typing import FrozenSet, List, Optional, cast
from urllib.parse import unquote, urlparse, urlunparse

from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field


if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -90,15 +90,14 @@ def __repr_args__(self: BaseModel) -> "ReprArgs":


class Channel(ZeroValRepr, BaseModel):
model_config = ConfigDict(frozen=True) # type: ignore

url: str
used_env_vars: FrozenSet[str] = Field(default=frozenset())

def __lt__(self, other: "Channel") -> bool:
return tuple(self.dict().values()) < tuple(other.dict().values())

class Config:
frozen = True

@classmethod
def from_string(cls, value: str) -> "Channel":
if "://" in value:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies = [
"ensureconda >=1.3",
"gitpython >=3.1.30",
"jinja2",
"pydantic >=1.8.1",
"pydantic >=1.10",
"pyyaml >= 5.1",
"ruamel.yaml",
'tomli; python_version<"3.11"',
Expand Down