Skip to content

Conversation

adriangb
Copy link
Member

Pyright now has provisional support for PEP 746: microsoft/pyright@ac7f6b7

@github-actions github-actions bot added relnotes-fix Used for bugfixes. relnotes-packaging Used for dependency changes. labels Jun 17, 2024
@adriangb adriangb requested a review from sydney-runkle June 17, 2024 20:49
@adriangb adriangb self-assigned this Jun 17, 2024
Copy link

cloudflare-workers-and-pages bot commented Jun 17, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 733d345
Status: ✅  Deploy successful!
Preview URL: https://fe362654.pydantic-docs.pages.dev
Branch Preview URL: https://bump-pyright.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Jun 17, 2024

CodSpeed Performance Report

Merging #9674 will not alter performance

Comparing bump-pyright (733d345) with main (8bcc900)

Summary

✅ 13 untouched benchmarks

Copy link
Contributor

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adriangb!

Looks great overall, just had a few follow up questions about parametrized TypeAdapters and some of the # type: ignore statements in the test_pipeline.py file :).

Comment on lines +6 to +9
# this test works by adding type ignores and having pyright fail with
# an unused type ignore error if the type checking isn't working
Annotated[str, validate_as(int)] # type: ignore
Annotated[str, validate_as(str).transform(lambda x: int(x))] # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

@@ -25,12 +25,12 @@

@pytest.mark.parametrize('potato_variation', ['potato', ' potato ', ' potato', 'potato ', ' POTATO ', ' PoTatO '])
def test_parse_str(potato_variation: str) -> None:
ta_lower = TypeAdapter(Annotated[str, validate_as(...).str_strip().str_lower()])
ta_lower = TypeAdapter[str](Annotated[str, validate_as(...).str_strip().str_lower()])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What error do we get if we don't explicitly parametrize the TypeAdapter? Is there any way for said type to be inferred from the annotation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not haha I'm guessing you would have already handled that, but just wanted to check. Guessing it's the whole generic can of worms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not until the TypeForm PEP gets merged...

I thought it used to end up as TypeAdapter[Any] but it seems like it doesn't now. Maybe because of 8a896c5?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, in my #9570 fix I kept the __init__ so that users would be forced to parametrize the TypeAdapter if the type checker can't use the first overload. But having an implicit fallback to TypeAdapter[Any] seems good as well

@@ -67,18 +67,18 @@ def test_ge_le_gt_lt(
@pytest.mark.parametrize(
'type_, pipeline, valid_cases, invalid_cases',
[
(int, validate_as(int).multiple_of(5), [5, 20, 0], [18, 7]),
(float, validate_as(float).multiple_of(2.5), [2.5, 5.0, 7.5], [3.0, 1.1]),
(int, validate_as(int).multiple_of(5), [5, 20, 0], [18, 7]), # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use an ignore here?

Copy link
Member Author

@adriangb adriangb Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It had to do with the typing of multiple_of. I'm still not 100% certain it's correct but since it's just typing good enough.

@@ -115,13 +115,13 @@ def test_interval_constraints(type_: Any, pipeline: Any, valid_cases: list[Any],
[
(
str,
validate_as(str).len(min_len=2, max_len=5),
validate_as(str).len(min_len=2, max_len=5), # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same q, why the ignore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was because some of the types like list where missing parametrization below (needs to be list[int])

@sydney-runkle sydney-runkle enabled auto-merge (squash) June 18, 2024 16:55
@sydney-runkle sydney-runkle merged commit 9dac684 into main Jun 18, 2024
@sydney-runkle sydney-runkle deleted the bump-pyright branch June 18, 2024 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes-fix Used for bugfixes. relnotes-packaging Used for dependency changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants