Skip to content

Tweak query param types - #175

Merged
lovelydinosaur merged 3 commits into
masterfrom
tweak-query-param-types
Jul 30, 2019
Merged

lovelydinosaur merged 3 commits into
masterfrom
tweak-query-param-types

Conversation

@lovelydinosaur

@lovelydinosaur lovelydinosaur commented Jul 30, 2019 •

Copy link
Copy Markdown
Member

Allow primitive data types for query params.

Closes #154

@lovelydinosaur

lovelydinosaur commented Jul 30, 2019 •

Copy link
Copy Markdown
Member Author

Later follow ups:

  • Allow typing.Union[PrimitiveData, typing.List[PrimitiveData]] for eg. {a: [1, 2, 3]} => a=1&a=2&a=3
  • Use same style for urlencoded and multipart data.
  • Strictly enforcing types (TypeErrors against public interfaces.聽#122)
  • Nailing down exactly which composite types we want to enforce against. eg. For the list case, do we want typing.List, typing.Sequence, typing.Iterable. For the dict case, do we want typing.Mappingortyping.Dict`. Related to TypeErrors against public interfaces.聽#122.
  • Perhaps handle Decimal, Date, Time, DateTime, UUID?

Let's treat those as separate issues.

@lovelydinosaur

Copy link
Copy Markdown
Member Author

Thanks for the look-over, @pquentin!

@lovelydinosaur
lovelydinosaur merged commit 66754ad into master Jul 30, 2019
@sethmlarson
sethmlarson deleted the tweak-query-param-types branch July 30, 2019 23:27
@sethmlarson

Copy link
Copy Markdown
Contributor

Sorry for not getting my review in on this! This implementation can't emit a query key without a value (ie: ?q, different than an empty value ?q=)

@lovelydinosaur

Copy link
Copy Markdown
Member Author

This implementation can't emit a query key without a value (ie: ?q, different than an empty value ?q=

Yup. I鈥檓 very okay with that - I don鈥檛 think we should distinguish between the two cases, although I鈥檇 be happy with confirming which of the two styles browser form inputs end up with. If users need that use case for something esoteric, then they can use explicit string query strings.

Comment thread httpx/utils.py
return value.encode(encoding or "ascii")


def str_query_param(value: typing.Union[str, int, float, bool, type(None)]) -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there any obstacles to using PrimitiveData? for consistency

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. We'd need some tweaking to avoid a cyclical dependency.

@StephenBrown2

Copy link
Copy Markdown
Contributor

Following up on my comment last week, turns out the API I'm implementing a client for dies if the optional param is present whether or not the key has an = after it, so roundtripping is the only sane way for me. 鈽濓笍 looks good to me though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Change QueryParams(key=None) to not emit a parameter

5 participants