Skip to content

Immutable QueryParams - #1600

Merged
lovelydinosaur merged 3 commits into
masterfrom
immutable-queryparams
Apr 26, 2021
Merged

Immutable QueryParams#1600
lovelydinosaur merged 3 commits into
masterfrom
immutable-queryparams

Conversation

@lovelydinosaur

Copy link
Copy Markdown
Contributor

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")
assertq==httpx.QueryParams("a=123")
q=q.add("a", "456")
assertq==httpx.QueryParams("a=123&a=456")
q=q.remove("a")
assertq==httpx.QueryParams("")
q=q.merge({"b": "789"})
assertq==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.

@lovelydinosaurlovelydinosaur added the user-experience Ensuring that users have a good experience using the library label Apr 26, 2021
@lovelydinosaurlovelydinosaur added this to the v0.18 milestone Apr 26, 2021
@lovelydinosaur

Copy link
Copy Markdown
ContributorAuthor

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...

@lovelydinosaur
lovelydinosaur merged commit 2abb2f2 into masterApr 26, 2021
@lovelydinosaur
lovelydinosaur deleted the immutable-queryparams branch April 26, 2021 13:57
@lovelydinosaurlovelydinosaur mentioned this pull request Apr 26, 2021
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

user-experienceEnsuring that users have a good experience using the library

Development

Successfully merging this pull request may close these issues.

1 participant

@lovelydinosaur