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

Outline of making optional paramters explicit as Union with None #1760

Closed
wants to merge 1 commit into from

Conversation

dctr
Copy link

@dctr dctr commented Jul 21, 2021

Related discussion

Approaching the task of making optional parameters explicit by making the respective types a Union[..., None] to conform with existing coding conventions.

  • Add None to Unions of existing types where possible
  • Where parameters are classes or other Non-Union types, use Optional[T]
  • Import needed types from typing directly to avoid noisy prefixing

This approach fails for RequestFiles in _content.py > encode_request(). The method does a None-check on the files parameter, from where onwards the value can not be None anymore. And _multipart.py > _iter_fields() requires an iterator on the type, which all types suffice, except for None of course.

As outlined in the linked discussion, using Optional[T] for optional types will solve this, as up until encode_request() the parameter could be Optional[RequestFiles] and just RequestFiles after the None-check.

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.

1 participant