Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Addexperimental_allow_partial support#10748

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sydney-runkle merged 15 commits intomainfromallow_partial
Nov 4, 2024
Merged

Conversation

samuelcolvin
Copy link
Member

@samuelcolvinsamuelcolvin commentedOct 31, 2024
edited
Loading

This relies on:

So farallow_partial support is only implemented on validators for the following types:

  • list
  • set
  • frozenset
  • dict (e.g.dict[X, Y])
  • TypedDict

There are 2 fundamental things introduced:

  • (in jiter) support for parsing partial json, e.g. any valid JSON input which "stops early", for example[1, 2, "thr
  • (in pydantic-core) support for ignoring errors while validating the last item in a sequence or last value in a mapping (the last item can be invalid because the original data stopped part way through its definition)

Example:

frompydanticimportTypeAdapter,BaseModelfromtypingimportLiteralclassUserRecord(BaseModel):id:intname:strrole:Literal['admin','user']ta=TypeAdapter(list[UserRecord])# allow_partial if the input is a python objectd=ta.validate_python(    [        {'id':'1','name':'Alice','role':'user'},        {'id':'1','name':'Ben','role':'user'},        {'id':'1','name':'Char'},    ],experimental_allow_partial=True,)print(d)#> [UserRecord(id=1, name='Alice', role='user'), UserRecord(id=1, name='Ben', role='user')]# allow_partial if the input is a json stringd=ta.validate_json('[{"id":"1","name":"Alice","role":"user"},{"id":"1","name":"Ben","role":"user"},{"id":"1","name":"Char"}]',experimental_allow_partial=True,)print(d)#> [UserRecord(id=1, name='Alice', role='user'), UserRecord(id=1, name='Ben', role='user')]

jowilf, devraj, pyth0nic, JonZeolla, SantosJMM, and yamanahlawat reacted with thumbs up emojiabodacs and francbartoli reacted with eyes emoji
@github-actionsgithub-actionsbot added the relnotes-fixUsed for bugfixes. labelOct 31, 2024
@codspeed-hqCodSpeed HQ
Copy link

codspeed-hqbot commentedOct 31, 2024
edited
Loading

CodSpeed Performance Report

Merging#10748 willnot alter performance

Comparingallow_partial (3ea36b0) withmain (b4308e0)

Summary

✅ 44 untouched benchmarks

@cloudflare-workers-and-pagesCloudflare Workers and Pages
Copy link

cloudflare-workers-and-pagesbot commentedOct 31, 2024
edited
Loading

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit:3ea36b0
Status: ✅  Deploy successful!
Preview URL:https://ad0fa9a1.pydantic-docs.pages.dev
Branch Preview URL:https://allow-partial.pydantic-docs.pages.dev

View logs

@samuelcolvinsamuelcolvin added relnotes-feature and removed relnotes-fixUsed for bugfixes. labelsOct 31, 2024
@github-actionsGitHub Actions
Copy link
Contributor

github-actionsbot commentedOct 31, 2024
edited
Loading

Coverage report

This PR does not seem to contain any modification to coverable code.

@samuelcolvinsamuelcolvin changed the titleAddexperimental_allow_partial support toTypeAdapterAddexperimental_allow_partial supportOct 31, 2024
Copy link
Contributor

@sydney-runklesydney-runkle left a comment

Choose a reason for hiding this comment

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

This is super exciting overall - definitely a fan of theexperimental_ prefix for now. I'm impressed with the turnaround here.

A few follow up questions:

  • We should add a section to theexperimental docs talking about this flag (happy to have this between the beta and official release)
  • I'm wondering, does it make sense to only have this as a runtime flag? Should we also have a config setting for this - we have one forcache_strings, which I believe has a similar flow down tojitter? Even if not on config, I think we should make this accessible for fields in models, typed dicts, etc.

As a general note on the above, I feel we don't have a super clear system for when something belongs as a:

  • Runtime flag
  • Config setting
  • Annotation
  • Field setting

And we should probably document that to guide consistency in future development.

Copy link
Contributor

@hyperlint-aihyperlint-aibot left a comment

Choose a reason for hiding this comment

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

1 files reviewed, 2 total issue(s) found.

The style guide flagged several spelling errors that seemed like false positives. We skipped posting inline suggestions for the following words:

  • [Aa]nnotated_types

Copy link
Contributor

@hyperlint-aihyperlint-aibot left a comment

Choose a reason for hiding this comment

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

The style guide flagged several spelling errors that seemed like false positives. We skipped posting inline suggestions for the following words:

  • annotated_types

Copy link
Contributor

@hyperlint-aihyperlint-aibot left a comment

Choose a reason for hiding this comment

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

1 files reviewed, 3 total issue(s) found.

samuelcolvinand others added4 commitsNovember 3, 2024 11:56
Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
Copy link
Contributor

@hyperlint-aihyperlint-aibot left a comment

Choose a reason for hiding this comment

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

1 files reviewed, 3 total issue(s) found.

Copy link
Contributor

@hyperlint-aihyperlint-aibot left a comment

Choose a reason for hiding this comment

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

The style guide flagged several spelling errors that seemed like false positives. We skipped posting inline suggestions for the following words:

  • jiter

Copy link
Contributor

@sydney-runklesydney-runkle left a comment

Choose a reason for hiding this comment

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

Amazing!

Thanks for including such thorough docs - those will be easy to move to the concepts section, eventually!

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

@hyperlint-aihyperlint-ai[bot]hyperlint-ai[bot] left review comments

@sydney-runklesydney-runklesydney-runkle approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@samuelcolvin@sydney-runkle

[8]ページ先頭

©2009-2025 Movatter.jp