-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add typing to ParserMethod #350
base: main
Are you sure you want to change the base?
Conversation
Assumes eager=False
I tried to fix #120 while keeping maintenance cost as close to zero as possible and compatibility with Python 3.8. Any upgrade of the targeted version would help simplifying the type hints greatly, but it is already functional as is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Not sure it's a good idea to assume that the return type for the methods will be non-None
, esp. when allow_none
can be set to True
. is there a good way to handle that?
src/environs/__init__.py
Outdated
_dict = typing.Dict[str, typing.Any] | ||
|
||
|
||
class ParserMethod(typing.Generic[_T]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-blocking nit: maybe should make this 'private' if it's not meant to be used
class ParserMethod(typing.Generic[_T]): | |
class _ParserMethod(typing.Generic[_T]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible without @overload
which has already been suggested before.
I guess the best we can do is combining the overloads from #120 with the shorter Generic
syntax. I added a commit to do that.
Co-authored-by: Steven Loria <[email protected]>
looks like there's still some mypy errors in CI--can you take a look at those? |
Assumes
eager=False
: parsers are shown to return their base type and neitherAny
norNone
.I think this should be fine as users should call
env.seal()
and either terminate or at least not use invalid values in case of errors.