Skip to content

Commit

Permalink
Use an overload to deal with default=None
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathis Ribet committed Aug 14, 2024
1 parent f58aeda commit e590932
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/environs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,21 @@
class _ParserMethod(typing.Generic[_T]):
"""Duck typing, do not use"""

def __call__( # type: ignore[empty-body]
@typing.overload # type: ignore[no-overload-impl]
def __call__(
self,
name: str,
default: typing.Any = ma.missing,
default: None,
subcast: typing.Optional[Subcast] = None,
**kwargs,
) -> typing.Optional[_T]: ...

@typing.overload
def __call__(
self,
name: str,
default: typing.Union[ma.utils._Missing, _T] = ma.missing,
subcast: typing.Optional[Subcast] = None,
*,
# Subset of relevant marshmallow.Field kwargs
load_default: typing.Any = ma.missing,
validate: typing.Union[
typing.Callable[[typing.Any], typing.Any],
typing.Iterable[typing.Callable[[typing.Any], typing.Any]],
None,
] = None,
required: bool = False,
allow_none: typing.Optional[bool] = None,
error_messages: typing.Optional[typing.Dict[str, str]] = None,
metadata: typing.Optional[typing.Mapping[str, typing.Any]] = None,
**kwargs,
) -> _T: ...

Expand Down

0 comments on commit e590932

Please sign in to comment.