Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🎨 Update internal types for Python 3.10#14898

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tiangolo merged 1 commit intomasterfromtypes-py39
Feb 11, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletionsfastapi/_compat/v2.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,11 @@
from typing import (
Annotated,
Any,
Literal,
Union,
cast,
get_args,
get_origin,
)

from fastapi._compat import lenient_issubclass, shared
Expand All@@ -32,7 +35,6 @@
from pydantic_core.core_schema import (
with_info_plain_validator_function as with_info_plain_validator_function,
)
from typing_extensions import Literal, get_args, get_origin

RequiredParam = PydanticUndefined
Undefined = PydanticUndefined
Expand DownExpand Up@@ -83,22 +85,22 @@ class ModelField:
field_info: FieldInfo
name: str
mode: Literal["validation", "serialization"] = "validation"
config:Union[ConfigDict,None] = None
config: ConfigDict |None = None

@property
def alias(self) -> str:
a = self.field_info.alias
return a if a is not None else self.name

@property
def validation_alias(self) ->Union[str,None]:
def validation_alias(self) -> str |None:
va = self.field_info.validation_alias
if isinstance(va, str) and va:
return va
return None

@property
def serialization_alias(self) ->Union[str,None]:
def serialization_alias(self) -> str |None:
sa = self.field_info.serialization_alias
return sa or None

Expand DownExpand Up@@ -143,7 +145,7 @@ def validate(
value: Any,
values: dict[str, Any] = {}, # noqa: B006
*,
loc: tuple[Union[int,str], ...] = (),
loc: tuple[int |str, ...] = (),
) -> tuple[Any, list[dict[str, Any]]]:
try:
return (
Expand All@@ -160,8 +162,8 @@ def serialize(
value: Any,
*,
mode: Literal["json", "python"] = "json",
include:Union[IncEx,None] = None,
exclude:Union[IncEx,None] = None,
include: IncEx |None = None,
exclude: IncEx |None = None,
by_alias: bool = True,
exclude_unset: bool = False,
exclude_defaults: bool = False,
Expand DownExpand Up@@ -202,7 +204,7 @@ def get_schema_from_model_field(
],
separate_input_output_schemas: bool = True,
) -> dict[str, Any]:
override_mode:Union[Literal["validation"],None] = (
override_mode: Literal["validation"] |None = (
None
if (separate_input_output_schemas or _has_computed_fields(field))
else "validation"
Expand DownExpand Up@@ -318,7 +320,7 @@ def serialize_sequence_value(*, field: ModelField, value: Any) -> Sequence[Any]:
return shared.sequence_annotation_to_type[origin_type](value) # type: ignore[no-any-return,index]


def get_missing_field_error(loc: tuple[Union[int,str], ...]) -> dict[str, Any]:
def get_missing_field_error(loc: tuple[int |str, ...]) -> dict[str, Any]:
error = ValidationError.from_exception_data(
"Field required", [{"type": "missing", "loc": loc, "input": {}}]
).errors(include_url=False)[0]
Expand DownExpand Up@@ -360,7 +362,7 @@ def get_cached_model_fields(model: type[BaseModel]) -> list[ModelField]:
# Duplicate of several schema functions from Pydantic v1 to make them compatible with
# Pydantic v2 and allow mixing the models

TypeModelOrEnum =Union[type["BaseModel"],type[Enum]]
TypeModelOrEnum = type["BaseModel"] |type[Enum]
TypeModelSet = set[TypeModelOrEnum]


Expand All@@ -377,7 +379,7 @@ def get_model_name_map(unique_models: TypeModelSet) -> dict[TypeModelOrEnum, str


def get_flat_models_from_model(
model: type["BaseModel"], known_models:Union[TypeModelSet,None] = None
model: type["BaseModel"], known_models: TypeModelSet |None = None
) -> TypeModelSet:
known_models = known_models or set()
fields = get_model_fields(model)
Expand DownExpand Up@@ -426,7 +428,7 @@ def get_flat_models_from_fields(


def _regenerate_error_with_loc(
*, errors: Sequence[Any], loc_prefix: tuple[Union[str,int], ...]
*, errors: Sequence[Any], loc_prefix: tuple[str |int, ...]
) -> list[dict[str, Any]]:
updated_loc_errors: list[Any] = [
{**err, "loc": loc_prefix + err.get("loc", ())} for err in errors
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp