Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: add
join
method toUrl
class #1378base: main
Are you sure you want to change the base?
feat: add
join
method toUrl
class #1378Changes from 3 commits
a7d9351
7ef57ba
e8bd322
8b70975
6a4fa06
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sorry I missed these in the last round of review. I think the difference between the
/
and//
operators here is subtle and hard to document.I think better we just have
/
, and make it so that it matches the default ofappend_trailing_slash=False
. This will also simplify testing, I think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay
__floordiv__
can be removed but I feel the__truediv__
should haveappend_trailing_slash=True
because this overloaded operator would likely be used to join multiple paths in shorter code. This behaviour would feel familiar to Python users, as it resemblespathlib
's path joining.For example,
With
append_trailing_slash=False
it would instead result inhttp://a/d
andfile:///home/user/pop
which I think is not what the user would expect.I chose to add
__floordiv__
too because it would simplify adding files at the end.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Yikes, there are so many subleties here!
It seems to me that our
.join()
method really works likeurllib.parse.urljoin
when it comes to semantics, e.g.versus pathlib's
Given these are inconsistent, I think we should perhaps back away from trying to have pathlib-like semantics at all.
Would you be open to the idea of dropping the operators from the PR completely, so we can get
.join()
merged? We could then open apydantic
issue to discuss the design of the operators and move forward with an implementation when there's consensus?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively we could also have
joinpath()
which works likePathlib
and doesn't accept query string or fragments as the whole input?And then could have
/
operator work likejoinpath
? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
joinpath()
would certainly make things cleaner. Should I implementjoinpath()
in this PR, or should we drop the operators for now and discuss it in the issues instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question. I think I'd prefer we just had
.join()
here and worried about.joinpath()
and the operators later. That said, there's potentially a desire to agree a sketch of the follow ups here. @pydantic/oss - any ideas?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think without comment from anyone else, let's just do
.join()
here and then follow-up with an issue in the mainpydantic
repo where we can discuss.joinpath()
and operators.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be great to have more time to discuss the semantics (does it need to match
urllib
? What about other libraries likefurl
? Should be double check with the current RFCs? We should also check what was said in this discussion).