wip
This commit is contained in:
parent
fec28df75f
commit
5ae6b86712
10 changed files with 312 additions and 39 deletions
6
examples/__init__.py
Normal file
6
examples/__init__.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
"""Example usage of expand_pydantic_args.
|
||||
|
||||
SPDX-FileCopyrightText: 2023-present Waylon S. Walker <waylon@waylonwalker.com>
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
"""
|
||||
|
|
@ -1,29 +1,94 @@
|
|||
"""Models defines a set of classes for representing people and their hair.
|
||||
|
||||
Classes:
|
||||
|
||||
* `Alpha`: A class for representing an alpha value.
|
||||
* `Color`: A class for representing a color.
|
||||
* `Hair`: A class for representing hair.
|
||||
* `Person`: A class for representing a person.
|
||||
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Alpha(BaseModel):
|
||||
a: int
|
||||
|
||||
"""A class for representing an alpha value."""
|
||||
|
||||
a: int = Field(
|
||||
...,
|
||||
description="The alpha value.",
|
||||
)
|
||||
|
||||
|
||||
class Color(BaseModel):
|
||||
r: int
|
||||
g: int
|
||||
b: int
|
||||
alpha: Alpha
|
||||
|
||||
"""A class for representing a color."""
|
||||
|
||||
r: int = Field(
|
||||
...,
|
||||
description="The red component of the color.",
|
||||
)
|
||||
g: int = Field(
|
||||
...,
|
||||
description="The green component of the color.",
|
||||
)
|
||||
b: int = Field(
|
||||
...,
|
||||
description="The blue component of the color.",
|
||||
)
|
||||
alpha: Alpha = Field(
|
||||
...,
|
||||
description="The alpha value of the color.",
|
||||
)
|
||||
|
||||
|
||||
class Hair(BaseModel):
|
||||
color: Color
|
||||
length: int
|
||||
|
||||
"""A class for representing hair."""
|
||||
|
||||
color: Color = Field(
|
||||
...,
|
||||
description="The color of the hair.",
|
||||
)
|
||||
length: int = Field(
|
||||
...,
|
||||
description="The length of the hair.",
|
||||
)
|
||||
|
||||
|
||||
class Person(BaseModel):
|
||||
name: str
|
||||
other_name: Optional[str] = None
|
||||
age: int
|
||||
email: Optional[str]
|
||||
pet: str = "dog"
|
||||
address: str = Field("123 Main St", description="Where the person calls home.")
|
||||
hair: Hair
|
||||
|
||||
"""A class for representing a person."""
|
||||
|
||||
name: str = Field(
|
||||
...,
|
||||
description="The name of the person.",
|
||||
)
|
||||
other_name: Optional[str] = Field(
|
||||
None,
|
||||
description="An optional other name for the person.",
|
||||
)
|
||||
age: int = Field(
|
||||
...,
|
||||
description="The age of the person.",
|
||||
)
|
||||
email: Optional[str] = Field(
|
||||
None,
|
||||
description="An optional email address for the person.",
|
||||
)
|
||||
pet: str = Field(
|
||||
"dog",
|
||||
description="The person's pet.",
|
||||
)
|
||||
address: str = Field(
|
||||
"123 Main St",
|
||||
description="Where the person calls home.",
|
||||
)
|
||||
hair: Hair = Field(
|
||||
...,
|
||||
description="The person's hair.",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
"""Example usage of expand_pydantic_args with the Person model.
|
||||
|
||||
SPDX-FileCopyrightText: 2023-present Waylon S. Walker <waylon@waylonwalker.com>
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
"""
|
||||
from pyannotate_runtime import collect_types
|
||||
|
||||
from examples.models import Person
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
"""Example usage of expand_pydantic_args with the Person model as a typer cli.
|
||||
|
||||
SPDX-FileCopyrightText: 2023-present Waylon S. Walker <waylon@waylonwalker.com>
|
||||
|
||||
SPDX-License-Identifier: MIT
|
||||
"""
|
||||
import typer
|
||||
|
||||
from examples.models import Person
|
||||
|
|
@ -11,6 +17,7 @@ app = typer.Typer(
|
|||
|
||||
@app.callback()
|
||||
def main() -> None:
|
||||
"""Set up typer."""
|
||||
return
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue