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

Update Mypy docs with correct output from Mypy #8395

Merged
merged 2 commits into from Dec 18, 2023
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 docs/contributing.md
Expand Up @@ -108,7 +108,7 @@ If you've made any changes to the documentation (including changes to function s
# Build documentation
make docs
# If you have changed the documentation, make sure it builds successfully.
# You can also use `make docs-serve` to serve the documentation at localhost:8000
# You can also use `pdm run mkdocs serve` to serve the documentation at localhost:8000
```

### Commit and push your changes
Expand Down
10 changes: 7 additions & 3 deletions docs/integrations/mypy.md
Expand Up @@ -25,13 +25,17 @@ print(m.middle_name) # not a model field!
Model() # will raise a validation error for age and list_of_ints
```

Without any special configuration, mypy catches one of the errors:
Without any special configuration, mypy does not catch the [missing model field annotation](https://docs.pydantic.dev/2.5/errors/usage_errors/#model-field-missing-annotation) and warns about the `list_of_ints` argument which Pydantic parses correctly:

```
16: error: "Model" has no attribute "middle_name" [attr-defined]
test.py:15: error: List item 1 has incompatible type "str"; expected "int" [list-item]
test.py:15: error: List item 2 has incompatible type "bytes"; expected "int" [list-item]
test.py:16: error: "Model" has no attribute "middle_name" [attr-defined]
test.py:17: error: Missing named argument "age" for "Model" [call-arg]
test.py:17: error: Missing named argument "list_of_ints" for "Model" [call-arg]
```

But [with the plugin enabled](#enabling-the-plugin), it catches both:
But [with the plugin enabled](#enabling-the-plugin), it gives the correct error:
```
9: error: Untyped fields disallowed [pydantic-field]
16: error: "Model" has no attribute "middle_name" [attr-defined]
Expand Down