shared.py — fastapi Source File
Architecture documentation for shared.py, a python file in the fastapi codebase. 12 imports, 3 dependents.
Entity Profile
Dependency Diagram
graph LR 3e898b29_4dd8_c417_2d9b_a84d867423b4["shared.py"] 65099b90_26c1_5db5_09e6_30dc0ea421e3["sys"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 65099b90_26c1_5db5_09e6_30dc0ea421e3 fb2d9376_ca24_f2b2_f130_cc10e9f2e732["types"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> fb2d9376_ca24_f2b2_f130_cc10e9f2e732 0dda2280_3359_8460_301c_e98c77e78185["typing"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 0dda2280_3359_8460_301c_e98c77e78185 9c2c9cad_dfd2_7d1a_1c6d_b8a448285db4["warnings"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 9c2c9cad_dfd2_7d1a_1c6d_b8a448285db4 36df6c22_bdda_c58d_8489_1b2bca07e51a["collections"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 36df6c22_bdda_c58d_8489_1b2bca07e51a 07d79a2e_d4e9_0bbb_be90_936274444c8c["collections.abc"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 07d79a2e_d4e9_0bbb_be90_936274444c8c 4cff5a35_9399_b238_3d2b_e2cca82878e1["dataclasses"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 4cff5a35_9399_b238_3d2b_e2cca82878e1 57435f98_d97c_449e_ad42_afacbc7e4272["types.py"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 57435f98_d97c_449e_ad42_afacbc7e4272 6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 6913fbd4_39df_d14b_44bb_522e99b65b90 29a6b845_447e_294b_f2b6_9af1ebef531e["pydantic.version"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 29a6b845_447e_294b_f2b6_9af1ebef531e 92a32603_fcc6_3319_3df3_78c953234d9f["starlette.datastructures"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 92a32603_fcc6_3319_3df3_78c953234d9f 87f0eda4_1c7f_c164_42ba_f715b8cf0a6b["typing_extensions"] 3e898b29_4dd8_c417_2d9b_a84d867423b4 --> 87f0eda4_1c7f_c164_42ba_f715b8cf0a6b aac750d7_00e7_a28d_9e64_89918311078b["__init__.py"] aac750d7_00e7_a28d_9e64_89918311078b --> 3e898b29_4dd8_c417_2d9b_a84d867423b4 3e134d50_38c1_8523_f518_6686c1d9752b["v2.py"] 3e134d50_38c1_8523_f518_6686c1d9752b --> 3e898b29_4dd8_c417_2d9b_a84d867423b4 style 3e898b29_4dd8_c417_2d9b_a84d867423b4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import sys
import types
import typing
import warnings
from collections import deque
from collections.abc import Mapping, Sequence
from dataclasses import is_dataclass
from typing import (
Annotated,
Any,
TypeVar,
Union,
)
from fastapi.types import UnionType
from pydantic import BaseModel
from pydantic.version import VERSION as PYDANTIC_VERSION
from starlette.datastructures import UploadFile
from typing_extensions import TypeGuard, get_args, get_origin
_T = TypeVar("_T")
# Copy from Pydantic: pydantic/_internal/_typing_extra.py
if sys.version_info < (3, 10):
WithArgsTypes: tuple[Any, ...] = (typing._GenericAlias, types.GenericAlias) # type: ignore[attr-defined]
else:
WithArgsTypes: tuple[Any, ...] = (
typing._GenericAlias, # type: ignore[attr-defined]
types.GenericAlias,
types.UnionType,
) # pyright: ignore[reportAttributeAccessIssue]
PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(".")[:2])
sequence_annotation_to_type = {
Sequence: list,
list: list,
tuple: tuple,
set: set,
frozenset: frozenset,
deque: deque,
}
sequence_types: tuple[type[Any], ...] = tuple(sequence_annotation_to_type.keys())
# Copy of Pydantic: pydantic/_internal/_utils.py with added TypeGuard
def lenient_issubclass(
cls: Any, class_or_tuple: Union[type[_T], tuple[type[_T], ...], None]
) -> TypeGuard[type[_T]]:
try:
return isinstance(cls, type) and issubclass(cls, class_or_tuple) # type: ignore[arg-type]
except TypeError: # pragma: no cover
if isinstance(cls, WithArgsTypes):
return False
raise # pragma: no cover
def _annotation_is_sequence(annotation: Union[type[Any], None]) -> bool:
// ... (157 more lines)
Domain
Subdomains
Functions
- WithArgsTypes()
- _annotation_is_complex()
- _annotation_is_sequence()
- annotation_is_pydantic_v1()
- field_annotation_is_complex()
- field_annotation_is_scalar()
- field_annotation_is_scalar_sequence()
- field_annotation_is_sequence()
- is_bytes_or_nonable_bytes_annotation()
- is_bytes_sequence_annotation()
- is_pydantic_v1_model_class()
- is_pydantic_v1_model_instance()
- is_uploadfile_or_nonable_uploadfile_annotation()
- is_uploadfile_sequence_annotation()
- lenient_issubclass()
- value_is_sequence()
Dependencies
- collections
- collections.abc
- dataclasses
- pydantic
- pydantic.version
- starlette.datastructures
- sys
- types
- types.py
- typing
- typing_extensions
- warnings
Source
Frequently Asked Questions
What does shared.py do?
shared.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Responses subdomain.
What functions are defined in shared.py?
shared.py defines 16 function(s): WithArgsTypes, _annotation_is_complex, _annotation_is_sequence, annotation_is_pydantic_v1, field_annotation_is_complex, field_annotation_is_scalar, field_annotation_is_scalar_sequence, field_annotation_is_sequence, is_bytes_or_nonable_bytes_annotation, is_bytes_sequence_annotation, and 6 more.
What does shared.py depend on?
shared.py imports 12 module(s): collections, collections.abc, dataclasses, pydantic, pydantic.version, starlette.datastructures, sys, types, and 4 more.
What files import shared.py?
shared.py is imported by 3 file(s): __init__.py, test_compat.py, v2.py.
Where is shared.py in the architecture?
shared.py is located at fastapi/_compat/shared.py (domain: FastAPI, subdomain: Responses, directory: fastapi/_compat).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free