Skip to content

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

Closed
dctr wants to merge 1 commit intoencode:masterfrom
dctr:union-none
Closed

Outline of making optional paramters explicit as Union with None#1760
dctr wants to merge 1 commit intoencode:masterfrom
dctr:union-none

Conversation

@dctr
Copy link
Copy Markdown

@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