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

Allow pydantic v2 using transitional v1 support #12888

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -16,7 +16,7 @@ smart-open>=5.2.1,<7.0.0
numpy>=1.15.0
requests>=2.13.0,<3.0.0
tqdm>=4.38.0,<5.0.0
pydantic>=1.7.4,!=1.8,!=1.8.1,<1.11.0
pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0
jinja2
langcodes>=3.2.0,<4.0.0
# Official Python utilities
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -58,7 +58,7 @@ install_requires =
tqdm>=4.38.0,<5.0.0
numpy>=1.15.0
requests>=2.13.0,<3.0.0
pydantic>=1.7.4,!=1.8,!=1.8.1,<1.11.0
pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0
jinja2
# Official Python utilities
setuptools
Expand Down
8 changes: 6 additions & 2 deletions spacy/pipeline/_edit_tree_internals/schemas.py
@@ -1,8 +1,12 @@
from collections import defaultdict
from typing import Any, Dict, List, Union

from pydantic import BaseModel, Field, ValidationError
from pydantic.types import StrictBool, StrictInt, StrictStr
try:
from pydantic.v1 import BaseModel, Field, ValidationError
from pydantic.v1.types import StrictBool, StrictInt, StrictStr
except ImportError:
from pydantic import BaseModel, Field, ValidationError # type: ignore
from pydantic.types import StrictBool, StrictInt, StrictStr # type: ignore
rmitsch marked this conversation as resolved.
Show resolved Hide resolved


class MatchNodeSchema(BaseModel):
Expand Down
41 changes: 28 additions & 13 deletions spacy/schemas.py
Expand Up @@ -16,19 +16,34 @@
Union,
)

from pydantic import (
BaseModel,
ConstrainedStr,
Field,
StrictBool,
StrictFloat,
StrictInt,
StrictStr,
ValidationError,
create_model,
validator,
)
from pydantic.main import ModelMetaclass
try:
from pydantic.v1 import (
BaseModel,
ConstrainedStr,
Field,
StrictBool,
StrictFloat,
StrictInt,
StrictStr,
ValidationError,
create_model,
validator,
)
from pydantic.v1.main import ModelMetaclass
except ImportError:
from pydantic import ( # type: ignore
BaseModel,
ConstrainedStr,
Field,
StrictBool,
StrictFloat,
StrictInt,
StrictStr,
ValidationError,
create_model,
validator,
)
from pydantic.main import ModelMetaclass # type: ignore
from thinc.api import ConfigValidationError, Model, Optimizer
from thinc.config import Promise

Expand Down
7 changes: 6 additions & 1 deletion spacy/tests/pipeline/test_initialize.py
@@ -1,5 +1,10 @@
import pytest
from pydantic import StrictBool

try:
from pydantic.v1 import StrictBool
except ImportError:
from pydantic import StrictBool # type: ignore

from thinc.api import ConfigValidationError

from spacy.lang.en import English
Expand Down
7 changes: 6 additions & 1 deletion spacy/tests/pipeline/test_pipe_factories.py
@@ -1,5 +1,10 @@
import pytest
from pydantic import StrictInt, StrictStr

try:
from pydantic.v1 import StrictInt, StrictStr
except ImportError:
from pydantic import StrictInt, StrictStr # type: ignore

from thinc.api import ConfigValidationError, Linear, Model

import spacy
Expand Down
7 changes: 6 additions & 1 deletion spacy/tests/test_misc.py
Expand Up @@ -3,7 +3,12 @@
from pathlib import Path

import pytest
from pydantic import ValidationError

try:
from pydantic.v1 import ValidationError
except ImportError:
from pydantic import ValidationError # type: ignore

from thinc.api import (
Config,
ConfigValidationError,
Expand Down