Skip to content

Commit b62cc29

Browse files
committed
fix Optional datatype not being counted as optional, skipping if statement.
1 parent 5331caa commit b62cc29

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/confkit/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from types import NoneType
1111
from typing import TYPE_CHECKING, ClassVar, overload
1212

13-
from .data_types import BaseDataType
13+
from .data_types import BaseDataType, Optional
1414
from .exceptions import InvalidConverterError, InvalidDefaultError
1515
from .sentinels import UNSET
1616

@@ -134,7 +134,8 @@ def validate_strict_type(self) -> None:
134134
self.__converted_type = type(self.__converted_value)
135135
default_value_type = type(self._data_type.default)
136136

137-
if self.optional and self.__converted_type in (default_value_type, NoneType):
137+
is_optional = self.optional or isinstance(self._data_type, Optional)
138+
if (is_optional) and self.__converted_type in (default_value_type, NoneType):
138139
# Allow None or the same type as the default value to be returned by the converter when _optional is True.
139140
return
140141
if self.__converted_type is not default_value_type:

0 commit comments

Comments
 (0)