-
Notifications
You must be signed in to change notification settings - Fork 292
feat: add build method back to multihosturl #730
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 build method back to multihosturl #730
Conversation
please review |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #730 +/- ##
==========================================
+ Coverage 93.65% 93.67% +0.01%
==========================================
Files 99 99
Lines 13970 14080 +110
Branches 25 25
==========================================
+ Hits 13084 13189 +105
- Misses 880 885 +5
Partials 6 6
Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #730 will not alter performancesComparing Summary
|
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'm impressived if this is your first foray into Rust, congrats.
Overall good start, but some things to add and alter.
src/url.rs
Outdated
#[classmethod] | ||
#[pyo3(signature=(*, scheme, host, user=None, password=None, port=None, path=None, query=None, fragment=None))] | ||
#[allow(clippy::too_many_arguments)] | ||
pub fn build( |
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.
this method be on both PyUrl
(with this signature), and PyMultiHostUrl
- I guess allowing multiple hosts.
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.
Thanks @samuelcolvin - not 100% sure what it is thats needed here, are you saying:
- Implement the method on PyUrl too
- Have PyMultiHostUrl call its ref_url.build for its build function? or implement differently logic for PyMultiHostUrl?
@samuelcolvin I think I've addressed your comments now |
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.
Design question: do we want these methods to return Url
/ MultiHostUrl
, rather than str
?
src/url.rs
Outdated
host: &str, | ||
user: Option<&str>, | ||
password: Option<&str>, | ||
port: Option<&str>, |
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 we want to accept multiple host/user/password/port combinations in MutiHostUrl.build
. Potentially easiest to accept these as MultiHostHost
arguments (see __init__.py
).
On the Rust side that would potentially be hosts: Vec<&PyDict>
where you could then extract each host in turn.
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.
Interestingly again the existing behaviour was that Url/MultiHostUrl had the same .build()
behaviour in V1, so thats what I've done here. Would be happy to change if that's what we think needs to be done! 🙂
Maybe! For this i reimplemented existing behaviour which returned |
👍 let's get feedback from @samuelcolvin whether to stick to the V1 design or to make breaking changes. |
FWIW I think rebasing should clear out the large claimed change in benchmarks. |
…dd-build-method-to-multihosturl
Thanks for the help there @davidhewitt! I think i've got an implementation with those changes done |
please review |
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.
Thank you for the many refinements, overall looks great!
If you're interested, I've put a rust style suggestion about using format!
in the Display
implementation of MultiHostUrlHost
. Additionally, a question about whether it makes sense to reuse that implementation instead of the match
statements you put around the place.
And finally, I've noticed that I defined MultiHostUrlHost
wrong and it probably should use an integer for the port 🙈 . This does raise the question if we should update the other port
arguments to be integers too?
Thanks @davidhewitt ! Made the changes you suggested 😄 left a question as well |
please review |
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! Just two final comments, and once we've decided on those, let's merge 🚀
…dd-build-method-to-multihosturl
@davidhewitt last comments addressed, should be GTG 🚀 |
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.
This is looking good to me, many thanks! I'll merge as soon as CI is green 👍
Yey! 🎉 |
Looks like MultiHostUrl.build() returns MultiHostUrl, not str. So type-hint is wrong.
pydantic_core version: 2.3.0 from pypi
Isinstance also fails. It breaks SQLAlchemy for example
|
|
@Kludex shouldn't it return str instance like in v1? Or it is planned to return MultiHostUrl in v2 |
Eh... You are literally in the PR that has the discussion about the design decision. |
Change Summary
Linked to pydantic/pydantic#6355 in pydantic. Essentially, we used to have a
build()
method on the AnyUrl class:However this seems to have been lost in the transition to v2. This PR attempts to re implement it. I'm new to rust so this may not be done right, however it seems to be working as expected for me. Any help pushing this forward would be appreciated.
Related issue number
pydantic/pydantic#6355
Checklist
pydantic-core
(except for expected changes)Selected Reviewer: @samuelcolvin