Skip to content

Commit 759ca5d

Browse files
authored
* Fix tests * Export plugin * Fix typing * Fix export
1 parent f45afdf commit 759ca5d

File tree

12 files changed

+1019
-91
lines changed

12 files changed

+1019
-91
lines changed

mypy.ini

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ ignore_errors = True
2525
[mypy-pydantic.*]
2626
ignore_errors = True
2727

28+
[mypy-pydantic_core.*]
29+
ignore_errors = True
30+
2831
[mypy-rich.*]
2932
ignore_errors = True
3033

noxfile.py

-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def test_pydantic(session: Session, pydantic: str) -> None:
126126
@session(python=PYTHON_VERSIONS, name="Mypy tests")
127127
def tests_mypy(session: Session) -> None:
128128
session.run_always("poetry", "install", "--with", "integrations", external=True)
129-
session._session.install("pydantic~=2.0.3") # type: ignore
130129

131130
session.run(
132131
"pytest",
@@ -156,7 +155,6 @@ def tests_pyright(session: Session) -> None:
156155
@session(name="Mypy", tags=["lint"])
157156
def mypy(session: Session) -> None:
158157
session.run_always("poetry", "install", "--with", "integrations", external=True)
159-
session._session.install("pydantic~=2.0.3") # type: ignore
160158

161159
session.run("mypy", "--config-file", "mypy.ini")
162160

poetry.lock

+972-56
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+7-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ freezegun = "^1.2.1"
6969
libcst = {version = ">=0.4.7,<1.2.0", optional = false}
7070
MarkupSafe = "2.1.3"
7171
nox = "^2023.4.22"
72-
nox-poetry = "^1.0.2"
72+
nox-poetry = "^1.0.3"
7373
opentelemetry-api = "<2"
7474
opentelemetry-sdk = "<2"
7575
pygments = "^2.3"
@@ -85,7 +85,7 @@ pytest-xdist = {extras = ["psutil"], version = "^3.1.0"}
8585
python-multipart = ">=0.0.5,<0.0.7"
8686
rich = {version = ">=12.5.1,<14.0.0", optional = false}
8787
sanic-testing = ">=22.9,<24.0"
88-
sentry-sdk = "^1.14.0"
88+
sentry-sdk = "^1.39.2"
8989
typer = {version = ">=0.7.0", optional = false}
9090
types-aiofiles = ">=22.1,<24.0"
9191
types-certifi = "^2021.10.8"
@@ -95,11 +95,12 @@ types-python-dateutil = "^2.8.19"
9595
types-toml = "^0.10.8"
9696
types-typed-ast = "^1.5.8"
9797
types-ujson = "^5.6.0"
98-
# added this here manually because poetry doesn't seem to be able to handle it =(
99-
botocore = "1.34.13"
98+
types-protobuf = "^4.23.0.1"
10099
mypy = "1.8.0"
101100
pytest-mypy-plugins = ">=1.10,<4.0"
102-
types-protobuf = "^4.23.0.1"
101+
poetry-plugin-export = "^1.6.0"
102+
# another bug in poetry
103+
urllib3 = "<2"
103104

104105
[tool.poetry.group.integrations]
105106
optional = true
@@ -112,7 +113,7 @@ Django = ">=3.2"
112113
fastapi = {version = ">=0.65.0", optional = false}
113114
flask = ">=1.1"
114115
quart = ">=0.19.3"
115-
pydantic = {version = ">1.6.1,<2.0", optional = false}
116+
pydantic = {version = ">=2.0", optional = false}
116117
pytest-aiohttp = "^1.0.3"
117118
pytest-django = {version = "^4.5"}
118119
sanic = ">=20.12.2"

strawberry/cli/debug_server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626

2727
paths = ["/", "/graphql"]
2828
for path in paths:
29-
app.add_route(path, graphql_app)
30-
app.add_websocket_route(path, graphql_app)
29+
app.add_route(path, graphql_app) # type: ignore
30+
app.add_websocket_route(path, graphql_app) # type: ignore

strawberry/experimental/pydantic/_compat.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ def new_type_supertype(type_: Any) -> Any:
3939
return type_.__supertype__
4040

4141
def get_model_fields(model: Type[BaseModel]) -> Dict[str, CompatModelField]:
42-
field_info: dict[str, FieldInfo] = model.model_fields # type: ignore[attr-defined]
42+
field_info: dict[str, FieldInfo] = model.model_fields
4343
new_fields = {}
4444
# Convert it into CompatModelField
4545
for name, field in field_info.items():
4646
new_fields[name] = CompatModelField(
4747
name=name,
48-
type_=field.annotation, # type: ignore[attr-defined]
49-
outer_type_=field.annotation, # type: ignore[attr-defined]
48+
type_=field.annotation,
49+
outer_type_=field.annotation,
5050
default=field.default,
5151
default_factory=field.default_factory,
52-
required=field.is_required(), # type: ignore[attr-defined]
52+
required=field.is_required(),
5353
alias=field.alias,
5454
# v2 doesn't have allow_none
5555
allow_none=False,
@@ -65,24 +65,24 @@ def get_model_fields(model: Type[BaseModel]) -> Dict[str, CompatModelField]:
6565
is_new_type,
6666
new_type_supertype,
6767
)
68-
from pydantic.utils import (
68+
from pydantic.utils import ( # type: ignore[no-redef]
6969
lenient_issubclass,
7070
smart_deepcopy,
7171
)
7272

73-
PYDANTIC_MISSING_TYPE = dataclasses.MISSING
73+
PYDANTIC_MISSING_TYPE = dataclasses.MISSING # type: ignore[assignment]
7474

7575
def get_model_fields(model: Type[BaseModel]) -> Dict[str, CompatModelField]:
7676
new_fields = {}
7777
# Convert it into CompatModelField
78-
for name, field in model.__fields__.items():
78+
for name, field in model.__fields__.items(): # type: ignore[attr-defined]
7979
new_fields[name] = CompatModelField(
8080
name=name,
8181
type_=field.type_,
8282
outer_type_=field.outer_type_,
8383
default=field.default,
8484
default_factory=field.default_factory,
85-
required=field.required, # type: ignore[arg-type]
85+
required=field.required,
8686
alias=field.alias,
8787
allow_none=field.allow_none,
8888
has_alias=field.has_alias,

tests/conftest.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ def pytest_collection_modifyitems(config: pytest.Config, items: List[pytest.Item
4242
item.add_marker(getattr(pytest.mark, marker))
4343

4444

45-
if sys.version_info < (3, 12):
46-
47-
@pytest.hookimpl
48-
def pytest_ignore_collect(
49-
collection_path: pathlib.Path, path: Any, config: pytest.Config
50-
):
51-
if "python_312" in collection_path.parts:
52-
return True
45+
@pytest.hookimpl
46+
def pytest_ignore_collect(
47+
collection_path: pathlib.Path, path: Any, config: pytest.Config
48+
):
49+
if sys.version_info < (3, 12) and "python_312" in collection_path.parts:
50+
return True
51+
52+
markers = config.getoption("-m")
53+
54+
# starlite has some issues with pydantic 2, which we
55+
# use in our dev deps, so we skip starlite unless
56+
# we're running the tests for it
57+
if "starlite" not in markers and "starlite" in collection_path.parts:
58+
return True

tests/experimental/pydantic/schema/test_mutation.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ def create_user(self, input: CreateUserInput) -> UserType:
8181
result = schema.execute_sync(query)
8282

8383
if IS_PYDANTIC_V2:
84-
assert result.errors[0].message == (
84+
assert result.errors[0].message.startswith(
8585
"1 validation error for User\n"
8686
"name\n"
8787
" String should have at least 2 characters [type=string_too_short, "
8888
"input_value='P', input_type=str]\n"
89-
" For further information visit "
90-
"https://errors.pydantic.dev/2.0.3/v/string_too_short"
9189
)
9290
else:
9391
assert result.errors[0].message == (
@@ -143,13 +141,11 @@ def create_user(self, input: CreateUserInput) -> UserType:
143141
result = schema.execute_sync(query)
144142

145143
if IS_PYDANTIC_V2:
146-
assert result.errors[0].message == (
144+
assert result.errors[0].message.startswith(
147145
"1 validation error for HobbyInputModel\n"
148146
"name\n"
149147
" String should have at least 2 characters [type=string_too_short, "
150148
"input_value='P', input_type=str]\n"
151-
" For further information visit "
152-
"https://errors.pydantic.dev/2.0.3/v/string_too_short"
153149
)
154150

155151
else:

tests/http/conftest.py

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def _get_http_client_classes() -> Generator[Any, None, None]:
3333
)
3434
except ImportError as e:
3535
client_class = None
36+
except Exception as e:
37+
# Starlite is not compatible with Pydantic 2 so we get an error
38+
# when importing it, for now we skip it, in future we'll remove
39+
# Starlite in favour of Litestar
40+
client_class = None
3641

3742
yield pytest.param(
3843
client_class,

tests/mypy/test_pydantic.decorators.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
186186
MyModelStrawberry(email="").to_pydantic()
187187
out: |
188-
- case: test_to_pydantic_kwargs_with_optional_default
188+
- case: test_to_pydantic_kwargs_with_default_none
189189
main: |
190190
from pydantic import BaseModel
191191
from typing import Optional
@@ -194,7 +194,7 @@
194194
195195
class MyModel(BaseModel):
196196
email: str
197-
password: Optional[str] # pydantic makes this implicit = None default
197+
password: Optional[str] = None
198198
199199
200200
@strawberry.experimental.pydantic.input(model=MyModel)

tests/views/schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _read_file(text_file: Upload) -> str:
3434
if isinstance(text_file, UploadFile):
3535
text_file = text_file.file._file # type: ignore
3636

37-
with contextlib.suppress(ModuleNotFoundError):
37+
with contextlib.suppress(Exception):
3838
from starlite import UploadFile as StarliteUploadFile
3939

4040
if isinstance(text_file, StarliteUploadFile):

tests/websockets/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def _get_http_client_classes() -> Generator[Any, None, None]:
2020
)
2121
except ImportError:
2222
client_class = None
23+
except Exception:
24+
# TODO: remove this when removing Starlite
25+
client_class = None
2326

2427
yield pytest.param(
2528
client_class,

0 commit comments

Comments
 (0)