Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
baz: int
class ChildWithNull(object):
@story
def x(I):
I.one
class ChildWithShrink(object):
@story
def x(I):
I.one
@x.contract
class Contract(BaseModel):
baz: int
class ChildAlias(object):
@story
def x(I):
I.one
@x.contract
class Contract(BaseModel):
foo: Dict[str, str]
bar: Dict[str, str]
baz: Dict[str, int]
class ParamChild(object):
def test_custom_init_subclass_params():
class DerivedModel(BaseModel):
def __init_subclass__(cls, something):
cls.something = something
# if this raises a TypeError, then there is a regression of issue 867:
# pydantic.main.MetaModel.__new__ should include **kwargs at the end of the
# method definition and pass them on to the super call at the end in order
# to allow the special method __init_subclass__ to be defined with custom
# parameters on extended BaseModel classes.
class NewModel(DerivedModel, something=2):
something = 1
assert NewModel.something == 2
from fastapi import Body, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: str = None
price: float
tax: float = None
class User(BaseModel):
username: str
full_name: str = None
@app.put("/items/{item_id}")
async def update_item(
*, item_id: int, item: Item, user: User, importance: int = Body(...)
):
results = {"item_id": item_id, "item": item, "user": user, "importance": importance}
return results
category: Optional[str]
@validator("category", pre=True, always=True)
def valid_categories(cls, v):
if v is None:
return None
if v not in ALL_OUTING_CATEGORIES:
raise ValueError(
f"outing_types '{v}' is invalid since it does not belong to set of possible outings type: {list(ALL_OUTING_CATEGORIES.keys())}"
)
else:
v = ALL_OUTING_CATEGORIES.get(v, {})
return v
class PlacesBboxResponse(BaseModel):
places: List[Any]
source: PoiSource
bbox: Optional[Tuple[float, float, float, float]] = Field(
description="Minimal bbox containing all results. `null` if no result is found. May be larger than or outside of the original bbox passed in the query if `?extend_bbox=true` was set.",
example=(2.32, 48.85, 2.367, 48.866),
)
bbox_extended: bool = Field(
description="`true` if `?extend_bbox=true` was set and search has been executed on an extended bbox, after no result was found in the original bbox passed in the query."
)
@validator("bbox")
def round_bbox_values(cls, v):
if v is None:
return v
return tuple(round(x, 6) for x in v)
class PhotoSizeModel(BaseModel): # Result
"""
This object represents one size of a photo or a file / sticker thumbnail.
https://core.telegram.org/bots/api#photosize
"""
file_id: str
file_unique_id: str
width: int
height: int
file_size: Optional[int]
# end class PhotoSize
class AnimationModel(BaseModel): # Media
"""
This object represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).
https://core.telegram.org/bots/api#animation
"""
file_id: str
file_unique_id: str
width: int
height: int
duration: int
thumb: Optional['PhotoSizeModel']
file_name: Optional[str]
mime_type: Optional[str]
file_size: Optional[int]
# end class Animation
question: str
options: List['PollOptionModel']
total_voter_count: int
is_closed: bool
is_anonymous: bool
type: str
allows_multiple_answers: bool
correct_option_id: Optional[int]
explanation: Optional[str]
explanation_entities: Optional[List['MessageEntityModel']]
open_period: Optional[int]
close_date: Optional[int]
# end class Poll
class LocationModel(BaseModel): # Media
"""
This object represents a point on the map.
https://core.telegram.org/bots/api#location
"""
longitude: float
latitude: float
# end class Location
class VenueModel(BaseModel): # Media
"""
This object represents a venue.
https://core.telegram.org/bots/api#venue
"""
from pydantic import BaseModel
class BarModel(BaseModel):
whatever: int
class FooBarModel(BaseModel):
banana: float
foo: str
bar: BarModel
m = FooBarModel(banana=3.14, foo='hello', bar={'whatever': 123})
print(m.copy(include={'foo', 'bar'}))
print(m.copy(exclude={'foo', 'bar'}))
print(m.copy(update={'banana': 0}))
print(id(m.bar), id(m.copy().bar))
# normal copy gives the same object reference for `bar`
print(id(m.bar), id(m.copy(deep=True).bar))
# deep copy gives a new object reference for `bar`
from pydantic import BaseModel, SecretStr, constr
from boucanpy.core import (
ConstrainedEmailStr,
ConstrainedSecretStr,
ConstrainedTokenStr,
)
class PasswordAuthForm(BaseModel):
username: ConstrainedEmailStr
password: ConstrainedSecretStr # TODO: constrain length
class MfaAuthForm(BaseModel):
token: ConstrainedTokenStr
from datetime import datetime
from typing import Optional
import uuid
from pydantic import BaseModel, ValidationError, validator
class Submission(BaseModel):
submit_id: str
username: str
problem_id: str
result: str
language: str
score: int
test_case: str
source_code: str
code_size: int
compile_message: str
created_at: Optional[datetime]
def __init__(
self,
submit_id: str,
username: str,
class DnsServerData(BaseModel):
id: int
name: str
zones: Optional[List[ForwardRef("ZoneData")]]
created_at: datetime
class HttpServerData(BaseModel):
id: int
name: str
zones: Optional[List[ForwardRef("ZoneData")]]
created_at: datetime
class DnsRecordData(BaseModel):
id: int
record: str
sort: int
zone_id: int
# zone: Optional[ZoneData]
class ZoneData(BaseModel):
id: int
ip: str
domain: str
is_active: bool
dns_server_id: Optional[int]
dns_server: Optional[DnsServerData]
dns_records: Optional[List[DnsRecordData]]
http_server_id: Optional[int]