Skip to content

Commit

Permalink
basic types
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 3, 2024
1 parent a2ae61b commit fade298
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
7 changes: 7 additions & 0 deletions packages/common-library/src/common_library/basic_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from enum import StrEnum

from pydantic_core import PydanticUndefined

# SEE https://github.com/fastapi/fastapi/blob/master/fastapi/_compat.py#L75-L78
#
# Use as default when default_factory
Undefined = PydanticUndefined


class LogLevel(StrEnum):
DEBUG = "DEBUG"
Expand Down
6 changes: 0 additions & 6 deletions packages/models-library/src/models_library/_compat.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Annotated, Any

from common_library.basic_types import Undefined
from pydantic import AnyUrl, BaseModel, Field

from ._compat import Undefined

_Unset: Any = Undefined


Expand Down
2 changes: 1 addition & 1 deletion packages/models-library/src/models_library/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from typing import Annotated, Any, Final, TypeAlias
from uuid import UUID

from common_library.basic_types import Undefined
from models_library.basic_types import ConstrainedStr
from models_library.folders import FolderID
from models_library.workspaces import WorkspaceID
from pydantic import BaseModel, ConfigDict, Field, HttpUrl, field_validator

from ._compat import Undefined
from .basic_regex import DATE_RE, UUID_RE_BASE
from .emails import LowerCaseEmailStr
from .projects_access import AccessRights, GroupIDStr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from copy import deepcopy
from typing import Annotated, Any, TypeAlias, Union

from common_library.basic_types import Undefined
from pydantic import (
BaseModel,
ConfigDict,
Expand All @@ -18,7 +19,6 @@
field_validator,
)

from ._compat import Undefined
from .basic_types import EnvVarKey, KeyIDStr
from .projects_access import AccessEnum
from .projects_nodes_io import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pathlib import Path
from typing import Annotated, Any, Final, Literal

from models_library._compat import Undefined
from common_library.basic_types import Undefined
from models_library.basic_types import SHA256Str
from models_library.callbacks_mapping import CallbacksMapping
from models_library.service_settings_labels import (
Expand Down
7 changes: 5 additions & 2 deletions packages/settings-library/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from collections.abc import Callable
from typing import Any

import pydantic
import pytest
import settings_library.base
from pydantic import BaseModel, ValidationError
Expand All @@ -23,6 +24,8 @@
)
from settings_library.email import SMTPSettings

pydantic_version = ".".join(pydantic.__version__.split(".")[:2])

S2 = json.dumps({"S_VALUE": 2})
S3 = json.dumps({"S_VALUE": 3})

Expand Down Expand Up @@ -180,7 +183,7 @@ def test_create_settings_class_without_environ_fails(
"loc": ("S_VALUE",),
"msg": "Field required",
"type": "missing",
"url": "https://errors.pydantic.dev/2.9/v/missing",
"url": f"https://errors.pydantic.dev/{pydantic_version}/v/missing",
}


Expand Down Expand Up @@ -310,7 +313,7 @@ class SettingsClassExt(SettingsClass):
"loc": ("INT_VALUE_TO_NOTHING",),
"msg": "Input should be a valid integer, unable to parse string as an integer",
"type": "int_parsing",
"url": "https://errors.pydantic.dev/2.9/v/int_parsing",
"url": f"https://errors.pydantic.dev/{pydantic_version}/v/int_parsing",
}


Expand Down

0 comments on commit fade298

Please sign in to comment.