From d9ff73929496ac155c1ab1752c99af41b00f4bdb Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Tue, 24 Oct 2023 19:18:44 -0400 Subject: [PATCH] Revert v1 namespace (#10) * Revert "update readme" This reverts commit 454df21851b7f675c4e3d7d794e249edeae21622. * Revert "update readme" This reverts commit a28d9497d50758ad85079127334ec3363149168b. * Revert "feat: add v1 namespace (#8)" This reverts commit 33b2662c20de8047bc7f44de1cdbda7b73f76d3d. * redo field stuff * undo change --- README.md | 13 +++++++------ src/pydantic_compat/__init__.py | 1 - src/pydantic_compat/v1.py | 16 ---------------- tests/test_base_model.py | 10 ---------- 4 files changed, 7 insertions(+), 33 deletions(-) delete mode 100644 src/pydantic_compat/v1.py diff --git a/README.md b/README.md index 078b444..e1c1586 100644 --- a/README.md +++ b/README.md @@ -101,17 +101,18 @@ pydantic version installed (without deprecation warnings): | `Model.__fields__` | `Model.model_fields` | | `Model.__fields_set__` | `Model.model_fields_set` | + ## `Field` notes - `pydantic_compat.Field` will remove outdated fields (`const`) and translate fields with new names: - | v1 name | v2 name | + | v1 name | v2 name | | ---------------- | ------------------- | - | `min_items` | `min_length` | - | `max_items` | `max_length` | - | `regex` | `pattern` | - | `allow_mutation` | `not frozen` | - | `metadata` | `json_schema_extra` | + | `min_items` | `min_length` | + | `max_items` | `max_length` | + | `regex` | `pattern` | + | `allow_mutation` | `not frozen` | + | `metadata` | `json_schema_extra` | - Don't use `var = Field(..., const='val')`, use `var: Literal['val'] = 'val'` it works in both v1 and v2 - No attempt is made to convert between v1's `unique_items` and v2's `Set[]` diff --git a/src/pydantic_compat/__init__.py b/src/pydantic_compat/__init__.py index 8f904c9..221899d 100644 --- a/src/pydantic_compat/__init__.py +++ b/src/pydantic_compat/__init__.py @@ -26,7 +26,6 @@ "BaseModel", ] - from ._shared import PYDANTIC2 if TYPE_CHECKING: diff --git a/src/pydantic_compat/v1.py b/src/pydantic_compat/v1.py deleted file mode 100644 index d532dfb..0000000 --- a/src/pydantic_compat/v1.py +++ /dev/null @@ -1,16 +0,0 @@ -"""This module is a try/except pass-through for the pydantic.v1 namespace. - -The pydantic.v1 namespace was added in pydantic v2. It contains the entire -pydantic v1 package. For packages that would like to unpin their 'pydantic<2' -dependency *without* needing to update all of their code to use the pydantic v2 api, -this provides a simple way to delay that update. - -This is different from the goal of pydantic_compat on the whole, which is to provide -an API translation layer that allows you to actually use pydantic v2 features -(e.g. rust-backed speed, etc...) while also being compatible with packages that pin -pydantic<2. -""" -try: - from pydantic.v1 import * # noqa -except ImportError: - from pydantic import * # type: ignore # noqa diff --git a/tests/test_base_model.py b/tests/test_base_model.py index abf989c..97fee39 100644 --- a/tests/test_base_model.py +++ b/tests/test_base_model.py @@ -118,13 +118,3 @@ class Model(PydanticCompatMixin, pydantic.BaseModel): # test extra with pytest.raises((ValueError, TypeError)): # (v1, v2) Model(extra=1) - - -def test_v1_namespace() -> None: - from pydantic_compat.v1 import BaseModel - - class Model(BaseModel): - x: int = 1 - - m = Model() - assert m.dict() == {"x": 1} # no warning