Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add config setting to avoid adding trailing slash to URLs#1719

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
samuelcolvin wants to merge4 commits intomain
base:main
Choose a base branch
Loading
fromno-trailing-slash

Conversation

samuelcolvin
Copy link
Member

Preparation for fixingpydantic/pydantic#7186

mcgfeller, tumbl3w33d, seandlg, and HenriBlacksmith reacted with thumbs up emoji
@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedMay 24, 2025
edited
Loading

CodSpeed Performance Report

Merging#1719 willnot alter performance

Comparingno-trailing-slash (660b112) withmain (e43c144)

Summary

✅ 157 untouched benchmarks

Comment on lines +173 to +174
Bound(Bound<'py,PyUrl>),
Owned(PyUrl),
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@davidhewitt is there a better way of doing this, or a better name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The point of this is to avoid allocating the Python object until it's absolutely needed. Maybe call itLazyUrlObject and have the variants be

Suggested change
Bound(Bound<'py,PyUrl>),
Owned(PyUrl),
Object(Bound<'py,PyUrl>),
Struct(PyUrl),

implFrom<PyUrl>forUrl{
fnfrom(value:PyUrl) ->Url{
value.lib_url
}
}

#[pymethods]
implPyUrl{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Possiblyquery#[getter] also needs this treatment?

Comment on lines +173 to +174
Bound(Bound<'py,PyUrl>),
Owned(PyUrl),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The point of this is to avoid allocating the Python object until it's absolutely needed. Maybe call itLazyUrlObject and have the variants be

Suggested change
Bound(Bound<'py,PyUrl>),
Owned(PyUrl),
Object(Bound<'py,PyUrl>),
Struct(PyUrl),

EitherUrl::Py(py_url) =>Ok(py_url),
EitherUrl::Rust(rust_url) =>Bound::new(py,PyUrl::new(rust_url)),
EitherUrl::Bound(py_url) =>Ok(py_url),
EitherUrl::Owned(py_url) =>Bound::new(py,py_url),
}
}
}

implCopyFromPyUrlforEitherUrl<'_>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Seeing this again, this looks like it probably should have beenAsRef<Url> andAsMut<Url> implementations.

Copy link
Member

@ViicosViicos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

PyUrl.path will still contain the trailing slash:

u=Url('https://example.com',add_trailing_slash=False)u.path#> '/'

Do we also want to remove it here?

ifself.remove_trailing_slash && s.ends_with('/'){
s =&s[..s.len() -1];
}
s
}

pubfn__repr__(&self) ->String{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Does__repr__() also need to be updated?

@@ -490,7 +514,11 @@ fn unicode_url(lib_url: &Url) -> String {
s
}
_ => s,
};
if remove_trailing_slash && s.ends_with('/') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think the point is to preserve the input, not always add or always strip. Can we keep track of the input ending with a trailing slash?

If not the config option is confusing: it should beremove_trailing_slash: bool = False to match the implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It seems that it is working as expected but I'm not entirely sure why:

u=Url('https://example.com/',add_trailing_slash=False)str(u)#> 'https://example.com/'

felixweinberger added a commit to modelcontextprotocol/python-sdk that referenced this pull requestJul 14, 2025
Pydantic's AnyUrl incorrectly adds trailing slashes to base URLs withoutpaths. This behavior is being fixed in pydantic-core PR #1719 and willbe available in Pydantic 2.12+.Instead of working around the issue, mark the test as expected to fail.This documents the known bug and will automatically alert when Pydanticfixes it (the test will XPASS with xfail_strict=true in pyproject.toml).Ref:pydantic/pydantic-core#1719
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@adriangbadriangbadriangb left review comments

@davidhewittdavidhewittdavidhewitt left review comments

@ViicosViicosViicos left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@samuelcolvin@adriangb@davidhewitt@Viicos

[8]ページ先頭

©2009-2025 Movatter.jp