Skip to content

Instantly share code, notes, and snippets.

@himself65
Created July 12, 2022 23:03
Show Gist options
  • Save himself65/85ea00a8ae8911d03d991f42c110ea6b to your computer and use it in GitHub Desktop.
Save himself65/85ea00a8ae8911d03d991f42c110ea6b to your computer and use it in GitHub Desktop.
Use pydantic to genrerate standard function type
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
# }
@himself65
Copy link
Author

image

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