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

Request to add URL.join() to correctly join/construct new URLs #9794

Open
3 of 13 tasks
Ravencentric opened this issue Jun 28, 2024 · 2 comments · May be fixed by pydantic/pydantic-core#1378
Open
3 of 13 tasks

Request to add URL.join() to correctly join/construct new URLs #9794

Ravencentric opened this issue Jun 28, 2024 · 2 comments · May be fixed by pydantic/pydantic-core#1378
Assignees
Labels
feature request urls Related to `Url` types

Comments

@Ravencentric
Copy link

Initial Checks

  • I have searched Google & GitHub for similar requests and couldn't find anything
  • I have read and followed the docs and still think this feature is missing

Description

A method to correctly join URLs:

>>> a = Url("https://example.com/")

>>> a.join("user/John")
Url('https://example.com/user/John')

>>> a.join("/user/John")
Url('https://example.com/user/John')

>>> a / "user" / "John" # Similar to pathlib's __truediv__? Would be quite neat but may be too confusing?
Url('https://example.com/user/John')

This would be really helpful when dealing with URLs, so you don't have to keep a track of / on your own.

Affected Components

@pydantic-hooky pydantic-hooky bot added the pending Awaiting a response / confirmation label Jun 28, 2024
@sydney-runkle sydney-runkle removed the pending Awaiting a response / confirmation label Jul 3, 2024
@sydney-runkle
Copy link
Member

PRs welcome! I can see this being useful for folks. We'll probably want to move the Url class out of pydantic-core eventually.

@Meetesh-Saini
Copy link

Hey @sydney-runkle, I would like to contribute to this feature request. I have written a draft function that works as follows for now:

>>> from pydantic_core import Url
>>> a = Url("http://example.com")
>>> a.join("a")
Url('http://example.com/a/')
>>> a.join("a", "b", "c")
Url('http://example.com/a/b/c/')
>>> a.join("a", no_trailing_slash=True)
Url('http://example.com/a')
>>> a.join("a", "b", "c", no_trailing_slash=True)
Url('http://example.com/a/b/c')

@Meetesh-Saini Meetesh-Saini linked a pull request Jul 29, 2024 that will close this issue
4 tasks
@sydney-runkle sydney-runkle added the urls Related to `Url` types label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request urls Related to `Url` types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants