Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

ribetm
Copy link
Contributor

@ribetm ribetm commented Jul 26, 2024

Assumes eager=False: parsers are shown to return their base type and neither Any nor None.

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.

Assumes eager=False
@ribetm
Copy link
Contributor Author

ribetm commented Jul 26, 2024

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.

@ribetm ribetm marked this pull request as ready for review July 26, 2024 21:31
Copy link
Owner

@sloria sloria left a 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?

_dict = typing.Dict[str, typing.Any]


class ParserMethod(typing.Generic[_T]):
Copy link
Owner

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

Suggested change
class ParserMethod(typing.Generic[_T]):
class _ParserMethod(typing.Generic[_T]):

Copy link
Contributor Author

@ribetm ribetm Aug 14, 2024

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.

@sloria
Copy link
Owner

sloria commented Aug 21, 2024

looks like there's still some mypy errors in CI--can you take a look at those?

@nfantone
Copy link

Found this while looking to add type hints to environs parsed variables. Having this would be great!

@sloria @ribetm Can I help here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants