Skip to content

Commit

Permalink
Update Mypy docs with correct output from Mypy (#8395)
Browse files Browse the repository at this point in the history
  • Loading branch information
parhamfh committed Dec 18, 2023
1 parent 395451f commit ed0fd9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit ed0fd9b

Please sign in to comment.