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

fix typing for optional arguments in interfaces #337

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

vmeurisse
Copy link
Contributor

Add missing Optional for method arguments.

This is the recommendation from pep-0484:

A past version of this PEP allowed type checkers to assume an optional type when the default value is None, as in this code:

def handle_employee(e: Employee = None): ...

This would have been treated as equivalent to:

def handle_employee(e: Optional[Employee] = None) -> None: ...

This is no longer the recommended behavior. Type checkers should move towards requiring the optional type to be made explicit.

@codecov-commenter
Copy link

Codecov Report

Merging #337 (3435c57) into master (d0a97fc) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #337   +/-   ##
=======================================
  Coverage   86.13%   86.13%           
=======================================
  Files          67       67           
  Lines        5879     5879           
  Branches     1218     1218           
=======================================
  Hits         5064     5064           
  Misses        596      596           
  Partials      219      219           
Impacted Files Coverage Δ
apischema/conversions/converters.py 89.47% <ø> (ø)
apischema/conversions/utils.py 72.09% <ø> (ø)
apischema/deserialization/__init__.py 98.97% <ø> (ø)
apischema/graphql/resolvers.py 84.96% <ø> (ø)
apischema/graphql/schema.py 86.87% <ø> (ø)
apischema/json_schema/schema.py 85.59% <ø> (ø)
apischema/json_schema/types.py 92.68% <ø> (ø)
apischema/objects/conversions.py 78.00% <ø> (ø)
apischema/objects/getters.py 83.33% <ø> (ø)
apischema/serialization/__init__.py 84.96% <ø> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d0a97fc...3435c57. Read the comment docs.

@wyfo
Copy link
Owner

wyfo commented Jan 28, 2022

Hi, thank you for your contribution!

Actually, I was aware of this deprecation, and I was planning to do it someday, but I kinda liked the old behavior, because it makes more obvious that the default value should not be used as an argument; there is indeed no interest to write deserialize(MyType, data, coerce=None) instead of deserialize(MyType, data).

That's why I took my time, but you're right, it's time to move on.

@wyfo wyfo merged commit af1bf4a into wyfo:master Jan 28, 2022
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.

None yet

3 participants