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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit Optional to types #44

Merged
merged 2 commits into from
Mar 15, 2022
Merged

Add explicit Optional to types #44

merged 2 commits into from
Mar 15, 2022

Conversation

jonathangreen
Copy link
Contributor

This PR adds Optional[] to type hints for parameters that can take None. This is useful when running mypy on code consuming Dunami as a library. Otherwise you get type errors from mypy when passing None as an argument to these functions.

error: Argument "metadata" to "serialize" of "Version" has incompatible type "Optional[bool]"; expected "bool"

I also updated the .pre-commit-config.yaml to run mypy with the --no-implicit-optional flag to catch parameters that should be marked as Optional in the future.

Thank you for the very helpful library! 馃檹馃徎

Copy link
Owner

@mtkennerly mtkennerly 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 this! I didn't realize that this style was now deprecated. For anyone else who stops by, here's the relevant note from PEP 484:

A past version of this PEP allowed type checkers to assume an optional type when the default value is None [...] This is no longer the recommended behavior. Type checkers should move towards requiring the optional type to be made explicit.

@mtkennerly mtkennerly merged commit 99bd0f1 into mtkennerly:master Mar 15, 2022
@mtkennerly mtkennerly added this to the v1.10.1 milestone Mar 15, 2022
@mtkennerly mtkennerly added the bug Something isn't working label Mar 15, 2022
mtkennerly added a commit that referenced this pull request Mar 15, 2022
@jonathangreen jonathangreen deleted the bugfix/optional_type branch March 15, 2022 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants