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

Immutable QueryParams #1600

Merged
merged 3 commits into from
Apr 26, 2021
Merged

Immutable QueryParams #1600

merged 3 commits into from
Apr 26, 2021

Conversation

tomchristie
Copy link
Member

As outlined in #1599.
Refs #1275.

Drop support for QueryParams.__setitem__ and QueryParams.update() in favour of an immutable-only interface, in line with our URL design. All manipulation methods now return new QueryParams instances:

q = httpx.QueryParams()

q = q.set("a", "123")
assert q == httpx.QueryParams("a=123")

q = q.add("a", "456")
assert q == httpx.QueryParams("a=123&a=456")

q = q.remove("a")
assert q == httpx.QueryParams("")

q = q.merge({"b": "789"})
assert q == httpx.QueryParams("b=789")

I've opted for a hard deprecation here, with .update() raising a RuntimeError, because immutability vs. mutability isn't something we ought to go "we're halfway there" on.

@tomchristie tomchristie added the user-experience Ensuring that users have a good experience using the library label Apr 26, 2021
@tomchristie tomchristie added this to the v0.18 milestone Apr 26, 2021
@tomchristie
Copy link
Member Author

I'm pushing on with this because it's something I've already been considering for a long time, and I've got other stuff that it's going to block unless I just push on with it, so...

@tomchristie tomchristie merged commit 2abb2f2 into master Apr 26, 2021
@tomchristie tomchristie deleted the immutable-queryparams branch April 26, 2021 13:57
@tomchristie tomchristie mentioned this pull request Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-experience Ensuring that users have a good experience using the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant