Skip to content

Fix circular import with validate_call - #10807

Merged
sydney-runkle merged 3 commits into
mainfrom
fix-circular-ref
Nov 11, 2024
Merged

sydney-runkle merged 3 commits into
mainfrom
fix-circular-ref

Conversation

@sydney-runkle

Copy link
Copy Markdown
Contributor

Fix #10799

@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Nov 10, 2024
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 10, 2024 •

Copy link
Copy Markdown

Deploying pydantic-docs with Β Cloudflare Pages Β Cloudflare Pages

Latest commit: 21f5813
Status:Β βœ…Β  Deploy successful!
Preview URL: https://4db4e229.pydantic-docs.pages.dev
Branch Preview URL: https://fix-circular-ref.pydantic-docs.pages.dev

View logs

@codspeed

codspeed Bot commented Nov 10, 2024 •

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #10807 will not alter performance

Comparing fix-circular-ref (21f5813) with main (421c2fb)

Summary

βœ… 44 untouched benchmarks

@github-actions

github-actions Bot commented Nov 10, 2024 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
Β Β pydantic
Β Β validate_call_decorator.py
Β Β pydantic/_internal
Β Β _generate_schema.py
Β Β _validate_call.py
Project Total Β 

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

@Viicos

Viicos commented Nov 10, 2024

Copy link
Copy Markdown
Member

It should be the other way around I think, the _generate_schema module should import VALIDATE_CALL_SUPPORTED_TYPES and ValidateCallSupportedTypes in an if TYPE_CHECKING: block/ inside the match_type call. More generally, this circular import is a sign that things are not properly isolated. I think it would make sense to define VALIDATE_CALL_SUPPORTED_TYPES and ValidateCallSupportedTypes in the _generate_schema module, and let _validate_call import from there. After all, a _call_schema isn't only limited to @validate_call, you can very much do TypeAdapter(some_callable).

@Viicos

Viicos commented Nov 11, 2024

Copy link
Copy Markdown
Member

Additionally, there's the test_init_export that was supposed to catch these issues

@pytest.mark.filterwarnings('ignore::DeprecationWarning')
def test_init_export():
for name in dir(pydantic):
getattr(pydantic, name)

but it probably requires cleaning sys.modules before each getattr call, and I couldn't make it work

@sydney-runkle

Copy link
Copy Markdown
Contributor Author

Additionally, there's the test_init_export that was supposed to catch these issues

I don't think this matters, as we're using two _internal files, so it's not supposed to catch them there...

@Viicos

Viicos commented Nov 11, 2024

Copy link
Copy Markdown
Member

Additionally, there's the test_init_export that was supposed to catch these issues

I don't think this matters, as we're using two _internal files, so it's not supposed to catch them there...

The idea is that we should have a test making sure that every from pydantic import x top level import works. This one does but because pydantic is already imported in various places (in different test files during pytest test collection, etc), it did not catch the circular import, and I find it a bit concerning as this could happen at any time

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

Development

Successfully merging this pull request may close these issues.

Circular ref error with validate_call

2 participants