Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test pyright with pydantic * rename file to avoid pytest running it * try another name 😴 * add docs about BaseSettings and Field * add change
- Loading branch information
1 parent
952fad2
commit c616dcb
Showing
6 changed files
with
101 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Typing checking with pyright in CI, improve docs on vscode/pylance/pyright. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[tool.pyright] | ||
extraPaths = ['../..'] | ||
reportUnnecessaryTypeIgnoreComment = true | ||
pythonVersion = '3.10' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
This file is used to test pyright's ability to check pydantic code. | ||
In particular pydantic provides the `@__dataclass_transform__` for `BaseModel` | ||
and all subclasses (including `BaseSettings`), see #2721. | ||
""" | ||
|
||
from typing import List | ||
|
||
from pydantic import BaseModel, BaseSettings, Field | ||
|
||
|
||
class MyModel(BaseModel): | ||
x: str | ||
y: List[int] | ||
|
||
|
||
m1 = MyModel(x='hello', y=[1, 2, 3]) | ||
|
||
m2 = MyModel(x='hello') # pyright: ignore | ||
|
||
|
||
class Knight(BaseModel): | ||
title: str = Field(default='Sir Lancelot') # this is okay | ||
age: int = Field(23) # this works fine at runtime but will case an error for pyright | ||
|
||
|
||
k = Knight() # pyright: ignore | ||
|
||
|
||
class Settings(BaseSettings): | ||
x: str | ||
y: int | ||
|
||
|
||
s1 = Settings.parse_obj({}) | ||
|
||
s2 = Settings() # pyright: ignore[reportGeneralTypeIssues] |