Created
July 12, 2022 23:03
-
-
Save himself65/85ea00a8ae8911d03d991f42c110ea6b to your computer and use it in GitHub Desktop.
Use pydantic to genrerate standard function type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pydantic.validators | |
def plus_a_b(a: int, b: int): | |
return a + b | |
result = pydantic.validate_arguments(plus_a_b) | |
print(result.model.schema_json(indent=2)) | |
# { | |
# "title": "PlusAB", | |
# "type": "object", | |
# "properties": { | |
# "a": { | |
# "title": "A", | |
# "type": "integer" | |
# }, | |
# "v__duplicate_kwargs": { | |
# "title": "V Duplicate Kwargs", | |
# "type": "array", | |
# "items": { | |
# "type": "string" | |
# } | |
# }, | |
# "b": { | |
# "title": "B", | |
# "type": "integer" | |
# }, | |
# "args": { | |
# "title": "Args", | |
# "type": "array", | |
# "items": {} | |
# }, | |
# "kwargs": { | |
# "title": "Kwargs", | |
# "type": "object" | |
# } | |
# }, | |
# "required": [ | |
# "a", | |
# "b" | |
# ], | |
# "additionalProperties": false | |
# } |
Author
himself65
commented
Jul 12, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment