def test_optional_types():
    """Optional and Union[T, None] must define a None default"""

    class Profile(DictValue):
        username: str

    # Good
    class Settings(Dynaconf):
        name: Optional[str] = None
        age: Optional[int] = None
        colors: Optional[list] = None
        profile: Optional[Profile] = None
        city: Union[str, None] = None
        team: Annotated[Optional[str], Validator()] = None
        work: NotRequired[dict]

    Settings(work={}, team="A")

    # Not Good
    class Settings(Dynaconf):
        name: Optional[str]  # Should have used NotRequired

    msg = "Optional Union must assign `None` explicitly as default."
    with pytest.raises(DynaconfSchemaError, match=msg):
        Settings()
Optional and Union[T, None] must define a None default
tests/test_typed.py