-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
No validation occurred after using Annotated. #6612
Comments
I am trying to change some of the code to the following code: Hour = Annotated[conint(gt=0, lt=25), int]
Minute = Annotated[conint(gt=0, lt=61), int] This can lead to validation and enable vscode Python type inference to work properly, but I'm not sure why. |
In v2 Lines 132 to 159 in c4b40f2
The pylance error is unfortunate, but you can still use the following: from typing import Annotated
from annotated_types import Interval
from pydantic import BaseModel
Hour = Annotated[int, Interval(gt=0, lt=25)]
Minute = Annotated[int, Interval(gt=0, lt=61)] |
It might make sense to do something similar to #6605 |
Here's a runnable version of the approach @Viicos suggested above: from typing import Annotated
from annotated_types import Interval
from pydantic import BaseModel, Field
Hour = Annotated[int, Field(gt=0, lt=25)]
Minute = Annotated[int, Interval(gt=0, lt=61)]
class TimeOne(BaseModel):
hour: Hour
minute: Minute
print(TimeOne(hour=-1, minute=10))
#> hour -> Input should be greater than 0 [type=greater_than, input_value=-1, input_type=int] Note that you can use |
Initial Checks
Description
Please take a look at this issue first: #5006
TimeOne can make VS Code Python type inference work properly, but TimeOne did not undergo validation.
Example Code
Python, Pydantic & OS Version
Selected Assignee: @adriangb
The text was updated successfully, but these errors were encountered: