Skip to content

Commit f5fd81e

Browse files
authored
Final QA (#518)
1 parent 11b2f7c commit f5fd81e

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

python-pydantic/pydantic_models.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Self
21
from datetime import date
3-
from uuid import UUID, uuid4
42
from enum import Enum
3+
from typing import Self
4+
from uuid import UUID, uuid4
5+
56
from pydantic import (
67
BaseModel,
78
EmailStr,
@@ -19,7 +20,7 @@ class Department(Enum):
1920

2021

2122
class Employee(BaseModel):
22-
employee_id: UUID = Field(default_factory=lambda: uuid4(), frozen=True)
23+
employee_id: UUID = Field(default_factory=uuid4, frozen=True)
2324
name: str = Field(min_length=1, frozen=True)
2425
email: EmailStr = Field(pattern=r".+@example\.com$")
2526
date_of_birth: date = Field(alias="birth_date", repr=False, frozen=True)
@@ -30,10 +31,10 @@ class Employee(BaseModel):
3031
@field_validator("date_of_birth")
3132
@classmethod
3233
def check_valid_age(cls, date_of_birth: date) -> date:
33-
date_delta = date.today() - date_of_birth
34-
age = date_delta.days / 365
34+
today = date.today()
35+
eighteen_years_ago = date(today.year - 18, today.month, today.day)
3536

36-
if age < 18:
37+
if date_of_birth > eighteen_years_ago:
3738
raise ValueError("Employees must be at least 18 years old.")
3839

3940
return date_of_birth

python-pydantic/settings_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pydantic import HttpUrl, Field
1+
from pydantic import Field, HttpUrl
22
from pydantic_settings import BaseSettings, SettingsConfigDict
33

44

python-pydantic/validate_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
22
from typing import Annotated
3-
from pydantic import PositiveFloat, validate_call, Field, EmailStr
3+
4+
from pydantic import EmailStr, Field, PositiveFloat, validate_call
45

56

67
@validate_call

0 commit comments

Comments
 (0)