8000 Add `generate_arguments_schema()` function by Viicos · Pull Request #11572 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

Add generate_arguments_schema() function #11572

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 5 commits into from
Mar 27, 2025
Merged

Conversation

Viicos
Copy link
Member
@Viicos Viicos commented Mar 17, 2025

Change Summary

Example usage:

from pydantic.validate_call_decorator import SKIP, generate_arguments_schema

def func(context: RunContext[str], a: int):
    pass

def callback(index: int, name: str, hint: Any):
    if index == 0 and hint is RunContext or get_origin(hint) is RunContext:
        return SKIP
    # Do other checks as well, e.g. RunContext in another position, etc.

generate_arguments_schema(
    func,
    schema_type='arguments-v3',
    parameters_callback=callback 
)
"""
{
│   'type': 'arguments-v3',
│   'arguments_schema': [{'name': 'a', 'schema': {'type': 'int', 'metadata': {}}, 'mode': 'positional_or_keyword'}],
│   'validate_by_name': False
}
"""

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

< 8000 div data-view-component="true" class="comment-reactions js-reactions-container js-reaction-buttons-container social-reactions reactions-container d-flex">
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Mar 17, 2025
Copy link
cloudflare-workers-and-pages bot commented Mar 17, 2025

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: f2e7385
Status: ✅  Deploy successful!
Preview URL: https://457e5e83.pydantic-docs.pages.dev
Branch Preview URL: https://generate-arguments-schema-fu.pydantic-docs.pages.dev

View logs

Copy link
codspeed-hq bot commented Mar 17, 2025

CodSpeed Performance Report

Merging #11572 will not alter performance

Comparing generate-arguments-schema-func (f2e7385) with main (72bea3f)

Summary

✅ 46 untouched benchmarks

Base automatically changed from generic-unpack to main March 18, 2025 09:43
@Viicos Viicos force-pushed the generate-arguments-schema-func branch from 51c0343 to f036133 Compare March 20, 2025 15:43
Copy link
Member
@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

Overall looks good, needs tests etc.

Questions:

  • do we want to mark this as experimental? I don't mind, just checking
  • should we add schema_type as a kwarg to validate_call?

@Viicos
Copy link
Member Author
Viicos commented Mar 25, 2025

do we want to mark this as experimental? I don't mind, just checking

I moved it to the experimental module.

should we add schema_type as a kwarg to validate_call?

We could, this shouldn't change anything as @validate_call only allows validation from Python inputs (ArgsKwargs, and they are roughly equivalent between the two arguments schema).

This comment was marked as resolved.

@Viicos Viicos force-pushed the generate-arguments-schema-func branch 3 times, most recently from 8fbf1e6 to 29ca5dd Compare March 26, 2025 17:14
Copy link
Contributor
github-actions bot commented 8000 Mar 26, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _generate_schema.py
  _schema_gather.py
  pydantic/experimental
  arguments_schema.py
Project Total  

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

@Viicos Viicos force-pushed the generate-arguments-schema-func branch 2 times, most recently from 646d160 to 889faf3 Compare March 26, 2025 21:50
@Viicos Viicos marked this pull request as ready for review March 26, 2025 21:50
@Viicos Viicos force-pushed the generate-arguments-schema-func branch from 889faf3 to ac686db Compare March 26, 2025 22:00
@Viicos Viicos force-pushed the generate-arguments-schema-func branch from 42b20e6 to 4dc83b2 Compare March 27, 2025 15:34
@Viicos Viicos force-pushed the generate-arguments-schema-func branch from 793a77e to 4781d20 Compare March 27, 2025 15:45
Copy link
Contributor
@dmontagu dmontagu left a comment

Choose a reason for hiding this comment

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

Please make the docs changes we've discussed, then lgtm

@Viicos Viicos merged commit e2c2e81 into main Mar 27, 2025
64 checks passed
@Viicos Viicos deleted the generate-arguments-schema-func branch March 27, 2025 17:13
@Viicos Viicos added relnotes-feature and removed relnotes-fix Used for bugfixes. labels Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0