Skip to content

Commit 62d50a9

Browse files
authored
feat: allow pydantic v2 usage (#15)
1 parent 31dc8d7 commit 62d50a9

File tree

15 files changed

+180
-152
lines changed

15 files changed

+180
-152
lines changed

poetry.lock

Lines changed: 145 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pydango/connection/graph_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def db_traverse(
9595
continue
9696

9797
if isinstance(relation_doc, LazyProxy):
98-
relation_doc = relation_doc.__instance__
98+
relation_doc = relation_doc.__instance__ # type: ignore[assignment]
9999

100100
if model.edges:
101101
for edge_field, obj in model.edges.__dict__.items():

pydango/orm/encoders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
from types import GeneratorType
66
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union
77

8-
from pydantic import BaseModel
9-
from pydantic.json import ENCODERS_BY_TYPE
8+
from pydantic.v1 import BaseModel
9+
from pydantic.v1.json import ENCODERS_BY_TYPE
1010

1111
SetIntStr = Set[Union[int, str]]
1212
DictIntStrAny = Dict[Union[int, str], Any]

pydango/orm/models/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
get_origin,
2020
)
2121

22-
from pydantic import BaseConfig, ConfigError, Field
23-
from pydantic.fields import SHAPE_SINGLETON, ModelField, PrivateAttr, Undefined
24-
from pydantic.main import BaseModel, ModelMetaclass
25-
from pydantic.typing import resolve_annotations
22+
from pydantic.v1 import BaseConfig, ConfigError, Field
23+
from pydantic.v1.fields import SHAPE_SINGLETON, ModelField, PrivateAttr, Undefined
24+
from pydantic.v1.main import BaseModel, ModelMetaclass
25+
from pydantic.v1.typing import resolve_annotations
2626

2727
from pydango.connection.consts import PYDANGO_SESSION_KEY
2828
from pydango.indexes import Indexes
@@ -41,8 +41,8 @@
4141
from pydango.query.expressions import FieldExpression, ObjectExpression
4242

4343
if TYPE_CHECKING:
44-
from pydantic.main import GetterDict, Model
45-
from pydantic.typing import AbstractSet, DictStrAny, MappingIntStrAny
44+
from pydantic.v1.main import GetterDict, Model
45+
from pydantic.v1.typing import AbstractSet, DictStrAny, MappingIntStrAny
4646

4747
from pydango.connection.session import PydangoSession
4848
from pydango.orm.models.types import RelationshipFields, Relationships

pydango/orm/models/edge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from abc import ABC
22
from typing import TYPE_CHECKING, Generic, Optional, TypeVar, Union
33

4-
from pydantic import BaseModel, Field
4+
from pydantic.v1 import BaseModel, Field
55

66
from pydango.orm.encoders import jsonable_encoder
77
from pydango.orm.models import BaseArangoModel, CollectionConfig, CollectionType
88
from pydango.query.consts import FROM, TO
99

1010
if TYPE_CHECKING:
11-
from pydantic.typing import DictStrAny
11+
from pydantic.v1.typing import DictStrAny
1212

1313
TEdge = TypeVar("TEdge", bound="EdgeModel")
1414

pydango/orm/models/fields.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import TYPE_CHECKING, Any, Dict, Optional, Type, Union, cast
22

3-
from pydantic.fields import ModelField
3+
from pydantic.v1.fields import ModelField
44

55
from pydango.orm.models.sentinel import LazyFetch
66
from pydango.query.expressions import (
@@ -11,7 +11,7 @@
1111
)
1212

1313
if TYPE_CHECKING:
14-
from pydantic.fields import LocStr, ModelOrDc, ValidateReturn
14+
from pydantic.v1.fields import LocStr, ModelOrDc, ValidateReturn
1515

1616
from pydango.orm.models.vertex import TVertexModel
1717
from pydango.query.expressions import QueryExpression

pydango/orm/models/relations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import TYPE_CHECKING, ForwardRef, Optional, Type
22

33
if TYPE_CHECKING:
4-
from pydantic.fields import ModelField
5-
from pydantic.typing import ReprArgs
4+
from pydantic.v1.fields import ModelField
5+
from pydantic.v1.typing import ReprArgs
66

77
from pydango.orm.models.base import LinkTypes
88
from pydango.orm.models.edge import TEdge

pydango/orm/models/shapes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic.fields import (
1+
from pydantic.v1.fields import (
22
SHAPE_FROZENSET,
33
SHAPE_ITERABLE,
44
SHAPE_LIST,

pydango/orm/models/vertex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
cast,
1111
)
1212

13-
from pydantic.fields import Field, ModelField
14-
from pydantic.main import create_model
15-
from pydantic.typing import evaluate_forwardref
13+
from pydantic.v1.fields import Field, ModelField
14+
from pydantic.v1.main import create_model
15+
from pydantic.v1.typing import evaluate_forwardref
1616

1717
from pydango.orm.consts import EDGES
1818
from pydango.orm.encoders import jsonable_encoder
@@ -24,7 +24,7 @@
2424
from pydango.orm.utils import evaluate_forward_ref, get_globals
2525

2626
if TYPE_CHECKING:
27-
from pydantic.typing import AbstractSetIntStr, DictStrAny, MappingIntStrAny
27+
from pydantic.v1.typing import AbstractSetIntStr, DictStrAny, MappingIntStrAny
2828

2929
TVertexModel = TypeVar("TVertexModel", bound="VertexModel")
3030
TEdges = TypeVar("TEdges", bound=EdgeData)

pydango/orm/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import sys
33
from typing import TYPE_CHECKING, Optional, Sequence, Type, Union, cast, overload
44

5-
from pydantic import BaseModel
6-
from pydantic.utils import lenient_issubclass
5+
from pydantic.v1 import BaseModel
6+
from pydantic.v1.utils import lenient_issubclass
77

88
from pydango.orm.encoders import jsonable_encoder
99
from pydango.orm.models.base import Aliased, BaseArangoModel, LazyProxy

pydango/orm/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import sys
22
from functools import lru_cache
33

4-
from pydantic.typing import evaluate_forwardref
4+
from pydantic.v1.typing import evaluate_forwardref
55

66

77
def get_globals(cls):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ version = "0.2.1"
100100
[tool.poetry.dependencies]
101101
aioarango = "^1.0.0"
102102
indexed = "^1.3.0"
103-
pydantic = "==1.10.12"
103+
pydantic = ">=1.10.17"
104104
python = ">=3.9,<4.0"
105105
urllib3 = "==1.26.15"
106106

tests/session/test_cities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55
from _pytest.fixtures import FixtureRequest
6-
from pydantic import Field
6+
from pydantic.v1 import Field
77
from pydiction import ANY_NOT_NONE, Matcher
88

99
from pydango.connection.session import PydangoSession

tests/session/test_family.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,28 +278,28 @@ async def test_save(session: PydangoSession, request: FixtureRequest):
278278
fiona.father = father
279279
fiona.mother = mother
280280

281-
fiona.edges = sister_edges.copy()
281+
fiona.edges = sister_edges.copy() # type: ignore[assignment]
282282

283283
jessica.sisters = [fiona]
284284
jessica.brothers = [ben, john]
285285
jessica.father = father
286286
jessica.mother = mother
287287

288-
jessica.edges = sister_edges.copy()
288+
jessica.edges = sister_edges.copy() # type: ignore[assignment]
289289

290290
john.sisters = [fiona, jessica]
291291
john.brothers = [ben]
292292
john.father = father
293293
john.mother = mother
294294

295-
john.edges = brother_edges.copy()
295+
john.edges = brother_edges.copy() # type: ignore[assignment]
296296

297297
ben.sisters = [fiona, jessica]
298298
ben.brothers = [john]
299299
ben.father = father
300300
ben.mother = mother
301301

302-
ben.edges = brother_edges.copy()
302+
ben.edges = brother_edges.copy() # type: ignore[assignment]
303303

304304
p = await session.save(john)
305305
request.config.cache.set("person_key", p.key) # type: ignore[union-attr]

tests/test_orm_query.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def test_simple_query():
3636
aql = orm_query.for_(User).filter(User.age > 10).sort(+User.age).return_(User)
3737
i = aql.orm_bound_vars[User]
3838
expected_repr = (
39-
f"FOR {repr(i)} IN <CollectionExpression: users> FILTER {repr(i)}.age > ? SORT {repr(i)}.age ASC RETURN"
40-
f" {repr(i)}"
39+
f"FOR {repr(i)} IN <CollectionExpression: users> FILTER {repr(i)}.age > ? SORT {repr(i)}.age ASC"
40+
f" RETURN {repr(i)}"
4141
)
4242
expected_compilation = "FOR var1 IN `users` FILTER var1.age > @param1 SORT var1.age ASC RETURN var1"
4343

@@ -51,8 +51,8 @@ def test_named_aliased():
5151
i = aql.orm_bound_vars[aliased_user]
5252
expected_compiled = "FOR u IN `users` FILTER u.age > @param1 SORT u.age DESC RETURN u"
5353
expected_repr = (
54-
f"FOR {repr(i)} IN <CollectionExpression: users> FILTER {repr(i)}.age > ? SORT {repr(i)}.age DESC RETURN"
55-
f" {repr(i)}"
54+
f"FOR {repr(i)} IN <CollectionExpression: users> FILTER {repr(i)}.age > ? SORT {repr(i)}.age DESC"
55+
f" RETURN {repr(i)}"
5656
)
5757

5858
assert repr(aql) == expected_repr
@@ -66,8 +66,8 @@ def test_aliased():
6666
i = aql.orm_bound_vars[aliased_user]
6767
expected_compiled = "FOR var1 IN `users` FILTER var1.age > @param1 SORT var1.age DESC RETURN var1"
6868
expected_repr = (
69-
f"FOR {repr(i)} IN <CollectionExpression: users> FILTER {repr(i)}.age > ? SORT {repr(i)}.age DESC RETURN"
70-
f" {repr(i)}"
69+
f"FOR {repr(i)} IN <CollectionExpression: users> FILTER {repr(i)}.age > ? SORT {repr(i)}.age DESC"
70+
f" RETURN {repr(i)}"
7171
)
7272

7373
assert repr(aql) == expected_repr

0 commit comments

Comments
 (0)