Skip to content

Conversation

sydney-runkle
Copy link
Contributor

@sydney-runkle sydney-runkle commented Oct 18, 2024

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:

  • Typechecking tests
  • Docs updates

You can still annotate things with UrlConstraints, but I'd recommend subclassing, especially if host_required=True and you want to get proper typing on host (it used to always be str | None as inherited from Url in pydantic-core, but now we control it on a class by class basis according to the corresponding host_required constraint).

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Oct 18, 2024
@sydney-runkle sydney-runkle changed the title first pass at url subclassing fix Migrate to subclassing instead of annotated approach for pydantic url types Oct 18, 2024
Copy link

codspeed-hq bot commented Oct 18, 2024

CodSpeed Performance Report

Merging #10662 will not alter performance

Comparing urls-proof-of-concept (fa3dad5) with main (bdb04ac)

Summary

✅ 44 untouched benchmarks

Copy link

cloudflare-workers-and-pages bot commented Oct 18, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

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'])
Copy link
Contributor Author

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',
Copy link
Contributor Author

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.

Copy link
Member

@Viicos Viicos left a 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!

Copy link
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic
  networks.py 110-118, 129-137, 165, 180, 266, 281, 297, 397, 420, 453, 521, 541, 562, 581
Project Total  

This report was generated by python-coverage-comment-action

@sydney-runkle sydney-runkle merged commit 27afdfc into main Oct 23, 2024
60 checks passed
@sydney-runkle sydney-runkle deleted the urls-proof-of-concept branch October 23, 2024 15:30
@anton-daneyko-ultramarin

@sydney-runkle Could it be that this PR made AnyHttpUrl unhashable? See #10955.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes.
Projects
None yet
4 participants