Skip to content

Conversation

@Viicos
Copy link
Member

@Viicos Viicos commented Jun 5, 2024

Change Summary

Fixes #9532

Dirty playgrounds if you want to play with it: pyright, mypy.

The only drawback is this is allowed:

ta = TypeAdapter[int](str)

As type checkers will fallback to the second overload. However, the following works as expected:

TypeAdapter(int)  # TypeAdapter[int], no type errors
TypeAdapter[int](int)  # TypeAdapter[int], no type errors
TypeAdapter[str | int](str | int)  # TypeAdapter[str | int], no type errors
TypeAdapter[int](Annotated[int, ...])  # TypeAdapter[int], no type errors

I think the TypeForm PEP is just around the corner, so this is really only a temporary fix until we get something working as expected for all use cases.

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @davidhewitt

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Jun 5, 2024
@codspeed-hq
Copy link

codspeed-hq bot commented Jun 5, 2024

CodSpeed Performance Report

Merging #9570 will not alter performance

Comparing Viicos:type-adapter-typing (edf747c) with main (137d4d8)

Summary

✅ 13 untouched benchmarks

@Viicos Viicos marked this pull request as ready for review June 5, 2024 11:55
@Viicos
Copy link
Member Author

Viicos commented Jun 5, 2024

Please review

@davidhewitt
Copy link
Contributor

@adriangb will pass this over to you, as it looks like you made the last edits to these points.

I think I agree with the PR here and we should wait for the TypeForm PEP to get perfect behaviour later, however want to let you make the final call.

@adriangb
Copy link
Member

adriangb commented Jun 5, 2024

Seems like we can't win here right now, we're going to have either false negatives or false positives. And I think the false positives are more annoying, so LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeAdapter with Union has Any type hint argument starting with Pydantic 2.7.0+

3 participants