Outline of making optional paramters explicit as Union with None #1760
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related discussion
Approaching the task of making optional parameters explicit by making the respective types a
Union[..., None]
to conform with existing coding conventions.None
to Unions of existing types where possibleOptional[T]
typing
directly to avoid noisy prefixingThis approach fails for
RequestFiles
in_content.py > encode_request()
. The method does aNone
-check on thefiles
parameter, from where onwards the value can not beNone
anymore. And_multipart.py > _iter_fields()
requires an iterator on the type, which all types suffice, except forNone
of course.As outlined in the linked discussion, using
Optional[T]
for optional types will solve this, as up untilencode_request()
the parameter could beOptional[RequestFiles]
and justRequestFiles
after theNone
-check.