-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Migrate to subclassing instead of annotated approach for pydantic url types #10662
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
Conversation
CodSpeed Performance ReportMerging #10662 will not alter performanceComparing Summary
|
Deploying pydantic-docs with
|
| Latest commit: |
fa3dad5
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fd4627a7.pydantic-docs.pages.dev |
| Branch Preview URL: | https://urls-proof-of-concept.pydantic-docs.pages.dev |
| UrlConstraints(allowed_schemes=['nats', 'tls', 'ws', 'wss'], default_host='localhost', default_port=4222), | ||
| ] | ||
| """A type that will accept any NATS DSN. | ||
| _constraints = UrlConstraints(allowed_schemes=['amqp', 'amqps']) |
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.
https://www.rabbitmq.com/docs/uri-spec
The host is "required" but can be zero in length... we previously didn't enforce host_required here, so leaving as is, but adding not to the docs.
| @@ -107,7 +107,6 @@ | |||
| 'http://example.org/path#fragment', | |||
| 'http://example.org/path?query#', | |||
| 'http://example.org/path?query#fragment', | |||
| 'file://localhost/foo/bar', | |||
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 don't think this is a valid AnyUrl because FileUrls don't require a host, but AnyUrls do.
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.
Seems like a clean implementation!
|
@sydney-runkle Could it be that this PR made AnyHttpUrl unhashable? See #10955. |
Fixes #9523
Fixes #7353
Fixes #10684
Sort of satisfying, I think #7353 is the first issue I opened (by directly copying / pasting a slack message, haha).
Depends on pydantic/pydantic-core#1488
Still need to add:
You can still annotate things with
UrlConstraints, but I'd recommend subclassing, especially ifhost_required=Trueand you want to get proper typing onhost(it used to always bestr | Noneas inherited fromUrlinpydantic-core, but now we control it on a class by class basis according to the correspondinghost_requiredconstraint).