-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Altering URLs #736
Comments
>>> URL("http://localhost:9090").build(port=8080)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/chey/work/vicinity/venv/lib/python3.10/site-packages/yarl/_url.py", line 216, in build
raise ValueError('Can\'t build URL with "port" but without "host".')
ValueError: Can't build URL with "port" but without "host". |
No, You can chain up multiple >>> URL("http://localhost:8080").with_host("newhost").with_port(80)
URL('http://newhost:80') Note that That said I'm +0 on adding a def with_(self, **kwargs):
new = self
for key, value in kwargs.items():
new = getattr(new, f"with_{key}")(value)
return new If this was added, the actual implementation would be a bit more robust, perhaps with cached mapping of known You can add the above locally if you want to: >>> def with_(self, **kwargs):
... new = self
... for key, value in kwargs.items():
... new = getattr(new, f"with_{key}")(value)
... return new
...
>>> URL.with_ = with_
>>> URL("http://localhost:8080").with_(host="newhost", port=80)
URL('http://newhost:80') |
Yes, it's clear |
|
Yes, that's what I was referring to. |
I did make a similar function to this in order to test out the idea. I suppose one could do a |
Is your feature request related to a problem?
No
Describe the solution you'd like
Would like the ability to alter single/multiple parts of a URL in single statement.
Example:
or this
Describe alternatives you've considered
N/A
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: