Skip to content

Fix circular import with validate_call #10807

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

Merged
merged 3 commits into from
Nov 11, 2024
Merged

Fix circular import with validate_call #10807

merged 3 commits into from
Nov 11, 2024

Conversation

sydney-runkle
Copy link
Contributor

Fix #10799

@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Nov 10, 2024
Copy link

cloudflare-workers-and-pages bot commented Nov 10, 2024

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

Copy link

codspeed-hq bot commented Nov 10, 2024

CodSpeed Performance Report

Merging #10807 will not alter performance

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

Summary

✅ 44 untouched benchmarks

Copy link
Contributor

github-actions bot commented Nov 10, 2024

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
Copy link
Member

Viicos commented Nov 10, 2024

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
Copy link
Member

Viicos commented Nov 11, 2024

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
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
Copy link
Member

Viicos commented Nov 11, 2024

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

@sydney-runkle sydney-runkle merged commit 96876ef into main Nov 11, 2024
54 checks passed
@sydney-runkle sydney-runkle deleted the fix-circular-ref branch November 11, 2024 22:17
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