diff --git a/src/_bentoml_impl/client/http.py b/src/_bentoml_impl/client/http.py index 10c2cdda363..e265b97f028 100644 --- a/src/_bentoml_impl/client/http.py +++ b/src/_bentoml_impl/client/http.py @@ -327,12 +327,14 @@ def _call( kwargs: dict[str, t.Any], *, headers: t.Mapping[str, str] | None = None, - ) -> t.Any: ... + ) -> t.Any: + ... @abstractmethod def _get_stream( self, endpoint: ClientEndpoint, args: t.Any, kwargs: t.Any - ) -> t.Any: ... + ) -> t.Any: + ... class SyncHTTPClient(HTTPClient[httpx.Client]): diff --git a/src/_bentoml_impl/serde.py b/src/_bentoml_impl/serde.py index aff7ac07ded..95054dd3ef6 100644 --- a/src/_bentoml_impl/serde.py +++ b/src/_bentoml_impl/serde.py @@ -28,16 +28,20 @@ class Serde(abc.ABC): media_type: str @abc.abstractmethod - def serialize_model(self, model: IODescriptor) -> bytes: ... + def serialize_model(self, model: IODescriptor) -> bytes: + ... @abc.abstractmethod - def deserialize_model(self, model_bytes: bytes, cls: type[T]) -> T: ... + def deserialize_model(self, model_bytes: bytes, cls: type[T]) -> T: + ... @abc.abstractmethod - def serialize(self, obj: t.Any) -> bytes: ... + def serialize(self, obj: t.Any) -> bytes: + ... @abc.abstractmethod - def deserialize(self, obj_bytes: bytes) -> t.Any: ... + def deserialize(self, obj_bytes: bytes) -> t.Any: + ... async def parse_request(self, request: Request, cls: type[T]) -> T: """Parse a input model from HTTP request""" diff --git a/src/_bentoml_sdk/api.py b/src/_bentoml_sdk/api.py index 5a5d4016237..c000b82a513 100644 --- a/src/_bentoml_sdk/api.py +++ b/src/_bentoml_sdk/api.py @@ -87,10 +87,12 @@ def __attrs_post_init__(self) -> None: self.output_spec.media_type = DEFAULT_STREAM_MEDIA_TYPE @t.overload - def __get__(self: T, instance: None, owner: type) -> T: ... + def __get__(self: T, instance: None, owner: type) -> T: + ... @t.overload - def __get__(self, instance: object, owner: type) -> t.Callable[P, R]: ... + def __get__(self, instance: object, owner: type) -> t.Callable[P, R]: + ... def __get__(self: T, instance: t.Any, owner: type) -> t.Callable[P, R] | T: from pydantic.fields import FieldInfo @@ -216,7 +218,8 @@ def _flatten_model_schema(model: type[IODescriptor]) -> dict[str, t.Any]: @t.overload -def api(func: t.Callable[t.Concatenate[t.Any, P], R]) -> APIMethod[P, R]: ... +def api(func: t.Callable[t.Concatenate[t.Any, P], R]) -> APIMethod[P, R]: + ... @t.overload @@ -230,7 +233,8 @@ def api( batch_dim: int | tuple[int, int] = ..., max_batch_size: int = ..., max_latency_ms: int = ..., -) -> t.Callable[[t.Callable[t.Concatenate[t.Any, P], R]], APIMethod[P, R]]: ... +) -> t.Callable[[t.Callable[t.Concatenate[t.Any, P], R]], APIMethod[P, R]]: + ... def api( diff --git a/src/_bentoml_sdk/service/dependency.py b/src/_bentoml_sdk/service/dependency.py index bbcd4603385..d8a3c74716e 100644 --- a/src/_bentoml_sdk/service/dependency.py +++ b/src/_bentoml_sdk/service/dependency.py @@ -54,10 +54,12 @@ def get( return _dependent_cache[key] @t.overload - def __get__(self, instance: None, owner: t.Any) -> Dependency[T]: ... + def __get__(self, instance: None, owner: t.Any) -> Dependency[T]: + ... @t.overload - def __get__(self, instance: t.Any, owner: t.Any) -> T: ... + def __get__(self, instance: t.Any, owner: t.Any) -> T: + ... def __get__(self, instance: t.Any, owner: t.Any) -> Dependency[T] | T: if instance is None: diff --git a/src/_bentoml_sdk/service/factory.py b/src/_bentoml_sdk/service/factory.py index 79a732ed181..b0239195869 100644 --- a/src/_bentoml_sdk/service/factory.py +++ b/src/_bentoml_sdk/service/factory.py @@ -46,7 +46,8 @@ HookF_ctx = t.TypeVar("HookF_ctx", bound=ContextFunc) class _ServiceDecorator(t.Protocol): - def __call__(self, inner: type[T]) -> Service[T]: ... + def __call__(self, inner: type[T]) -> Service[T]: + ... def with_config( @@ -324,11 +325,13 @@ def serve_http( @t.overload -def service(inner: type[T], /) -> Service[T]: ... +def service(inner: type[T], /) -> Service[T]: + ... @t.overload -def service(inner: None = ..., /, **kwargs: Unpack[Config]) -> _ServiceDecorator: ... +def service(inner: None = ..., /, **kwargs: Unpack[Config]) -> _ServiceDecorator: + ... def service(inner: type[T] | None = None, /, **kwargs: Unpack[Config]) -> t.Any: diff --git a/src/bentoml/_internal/bento/build_config.py b/src/bentoml/_internal/bento/build_config.py index 1397bad5cff..5e7494f0378 100644 --- a/src/bentoml/_internal/bento/build_config.py +++ b/src/bentoml/_internal/bento/build_config.py @@ -791,7 +791,8 @@ def __init__( python: PythonOptions | dict[str, t.Any] | None = ..., conda: CondaOptions | dict[str, t.Any] | None = ..., models: list[ModelSpec | str | dict[str, t.Any]] | None = ..., - ) -> None: ... + ) -> None: + ... def __attrs_post_init__(self) -> None: use_conda = not self.conda.is_empty() diff --git a/src/bentoml/_internal/client/__init__.py b/src/bentoml/_internal/client/__init__.py index dc64b2cabaa..2be587975b4 100644 --- a/src/bentoml/_internal/client/__init__.py +++ b/src/bentoml/_internal/client/__init__.py @@ -87,17 +87,18 @@ async def async_wait_until_server_ready( @t.overload @staticmethod - def from_url( - server_url: str, *, kind: None | t.Literal["auto"] = ... - ) -> Client: ... + def from_url(server_url: str, *, kind: None | t.Literal["auto"] = ...) -> Client: + ... @t.overload @staticmethod - def from_url(server_url: str, *, kind: t.Literal["http"] = ...) -> HTTPClient: ... + def from_url(server_url: str, *, kind: t.Literal["http"] = ...) -> HTTPClient: + ... @t.overload @staticmethod - def from_url(server_url: str, *, kind: t.Literal["grpc"] = ...) -> GrpcClient: ... + def from_url(server_url: str, *, kind: t.Literal["grpc"] = ...) -> GrpcClient: + ... @staticmethod def from_url( @@ -204,19 +205,22 @@ async def wait_until_server_ready( @classmethod async def from_url( cls, server_url: str, *, kind: None | t.Literal["auto"] = ... - ) -> AsyncGrpcClient | AsyncHTTPClient: ... + ) -> AsyncGrpcClient | AsyncHTTPClient: + ... @t.overload @classmethod async def from_url( cls, server_url: str, *, kind: t.Literal["http"] = ... - ) -> AsyncHTTPClient: ... + ) -> AsyncHTTPClient: + ... @t.overload @classmethod async def from_url( cls, server_url: str, *, kind: t.Literal["grpc"] = ... - ) -> AsyncGrpcClient: ... + ) -> AsyncGrpcClient: + ... @classmethod async def from_url( @@ -322,19 +326,22 @@ def wait_until_server_ready( @classmethod def from_url( cls, server_url: str, *, kind: None | t.Literal["auto"] = ... - ) -> SyncGrpcClient | SyncHTTPClient: ... + ) -> SyncGrpcClient | SyncHTTPClient: + ... @t.overload @classmethod def from_url( cls, server_url: str, *, kind: t.Literal["http"] = ... - ) -> SyncHTTPClient: ... + ) -> SyncHTTPClient: + ... @t.overload @classmethod def from_url( cls, server_url: str, *, kind: t.Literal["grpc"] = ... - ) -> SyncGrpcClient: ... + ) -> SyncGrpcClient: + ... @classmethod def from_url( diff --git a/src/bentoml/_internal/cloud/schemas/modelschemas.py b/src/bentoml/_internal/cloud/schemas/modelschemas.py index 57e9a06ff79..aa905dba39c 100644 --- a/src/bentoml/_internal/cloud/schemas/modelschemas.py +++ b/src/bentoml/_internal/cloud/schemas/modelschemas.py @@ -343,9 +343,9 @@ class DeploymentTargetConfig: deployment_strategy: t.Optional[DeploymentStrategy] = attr.field( default=None ) # Specific - bento_deployment_overrides: t.Optional[ApiServerBentoDeploymentOverrides] = ( - attr.field(default=None) - ) + bento_deployment_overrides: t.Optional[ + ApiServerBentoDeploymentOverrides + ] = attr.field(default=None) bento_request_overrides: t.Optional[BentoRequestOverrides] = attr.field( default=None ) # Put into image builder diff --git a/src/bentoml/_internal/context.py b/src/bentoml/_internal/context.py index c0162db0043..b9cd9e66702 100644 --- a/src/bentoml/_internal/context.py +++ b/src/bentoml/_internal/context.py @@ -81,12 +81,12 @@ def mutablecopy(self) -> Metadata: class ServiceContext: def __init__(self) -> None: - self._request_var: contextvars.ContextVar[ServiceContext.RequestContext] = ( - contextvars.ContextVar("request") - ) - self._response_var: contextvars.ContextVar[ServiceContext.ResponseContext] = ( - contextvars.ContextVar("response") - ) + self._request_var: contextvars.ContextVar[ + ServiceContext.RequestContext + ] = contextvars.ContextVar("request") + self._response_var: contextvars.ContextVar[ + ServiceContext.ResponseContext + ] = contextvars.ContextVar("response") # A dictionary for storing global state shared by the process self.state: dict[str, t.Any] = {} diff --git a/src/bentoml/_internal/external_typing/starlette.py b/src/bentoml/_internal/external_typing/starlette.py index 3045939dbf7..7c05b6fbeb0 100644 --- a/src/bentoml/_internal/external_typing/starlette.py +++ b/src/bentoml/_internal/external_typing/starlette.py @@ -10,7 +10,8 @@ from starlette.types import Send as ASGISend class AsgiMiddleware(t.Protocol): - def __call__(self, app: ASGIApp, **options: t.Any) -> ASGIApp: ... + def __call__(self, app: ASGIApp, **options: t.Any) -> ASGIApp: + ... __all__ = [ "AsgiMiddleware", diff --git a/src/bentoml/_internal/external_typing/tensorflow.py b/src/bentoml/_internal/external_typing/tensorflow.py index 60147ca4e4e..15a942acdfe 100644 --- a/src/bentoml/_internal/external_typing/tensorflow.py +++ b/src/bentoml/_internal/external_typing/tensorflow.py @@ -38,12 +38,14 @@ from tensorflow.python.eager.function import ConcreteFunction class GenericFunction(t.Protocol): - def __call__(self, *args: t.Any, **kwargs: t.Any): ... + def __call__(self, *args: t.Any, **kwargs: t.Any): + ... # NOTE: future proof when tensorflow decided to remove EagerTensor # and enable eager execution on Tensor by default. This class only serves # as type fallback. - class EagerTensor(Tensor): ... + class EagerTensor(Tensor): + ... class SignatureMap(t.Mapping[str, t.Any], Trackable): @@ -51,17 +53,22 @@ class SignatureMap(t.Mapping[str, t.Any], Trackable): _signatures: t.Dict[str, t.Union[ConcreteFunction, RestoredFunction, Function]] - def __init__(self) -> None: ... + def __init__(self) -> None: + ... def __getitem__( self, key: str - ) -> t.Union[ConcreteFunction, RestoredFunction, Function]: ... + ) -> t.Union[ConcreteFunction, RestoredFunction, Function]: + ... - def __iter__(self) -> t.Iterator[str]: ... + def __iter__(self) -> t.Iterator[str]: + ... - def __len__(self) -> int: ... + def __len__(self) -> int: + ... - def __repr__(self) -> str: ... + def __repr__(self) -> str: + ... # This denotes all decorated function with `tf.function` diff --git a/src/bentoml/_internal/frameworks/diffusers.py b/src/bentoml/_internal/frameworks/diffusers.py index e2a2a25c42e..5da553eb3bd 100644 --- a/src/bentoml/_internal/frameworks/diffusers.py +++ b/src/bentoml/_internal/frameworks/diffusers.py @@ -653,9 +653,9 @@ def get_runnable(bento_model: bentoml.Model) -> t.Type[bentoml.Runnable]: type[diffusers.DiffusionPipeline], _str2cls(pipeline_class) ) - scheduler_class: str | type[diffusers.SchedulerMixin] | None = ( - bento_options.scheduler_class - ) + scheduler_class: str | type[ + diffusers.SchedulerMixin + ] | None = bento_options.scheduler_class if scheduler_class and isinstance(scheduler_class, str): scheduler_class = t.cast( @@ -673,9 +673,9 @@ def get_runnable(bento_model: bentoml.Model) -> t.Type[bentoml.Runnable]: low_cpu_mem_usage: bool | None = bento_options.low_cpu_mem_usage variant: str | None = bento_options.variant _torch_dtype: str | torch.dtype | None = bento_options.torch_dtype - device_map: str | dict[str, int | str | torch.device] | None = ( - bento_options.device_map - ) + device_map: str | dict[ + str, int | str | torch.device + ] | None = bento_options.device_map load_pretrained_extra_kwargs = bento_options.load_pretrained_extra_kwargs support_lora = True if issubclass(pipeline_class, LoraLoaderMixin) else False diff --git a/src/bentoml/_internal/frameworks/transformers.py b/src/bentoml/_internal/frameworks/transformers.py index a6504d51208..9185f4fed58 100644 --- a/src/bentoml/_internal/frameworks/transformers.py +++ b/src/bentoml/_internal/frameworks/transformers.py @@ -56,14 +56,17 @@ class ModelDefaultMapping(t.TypedDict): class PreTrainedProtocol(t.Protocol): @property - def framework(self) -> str: ... + def framework(self) -> str: + ... - def save_pretrained(self, save_directory: str, **kwargs: t.Any) -> None: ... + def save_pretrained(self, save_directory: str, **kwargs: t.Any) -> None: + ... @classmethod def from_pretrained( cls, pretrained_model_name_or_path: str, *args: t.Any, **kwargs: t.Any - ) -> PreTrainedProtocol: ... + ) -> PreTrainedProtocol: + ... P = t.ParamSpec("P") @@ -359,13 +362,15 @@ def delete_pipeline(task: str) -> None: @t.overload def load_model( bento_model: str | Tag | Model, **kwargs: t.Any -) -> transformers.Pipeline: ... +) -> transformers.Pipeline: + ... @t.overload def load_model( bento_model: str | Tag | Model, *args: t.Any, **kwargs: t.Any -) -> TransformersPreTrained: ... +) -> TransformersPreTrained: + ... def load_model(bento_model: str | Tag | Model, *args: t.Any, **kwargs: t.Any) -> t.Any: diff --git a/src/bentoml/_internal/io_descriptors/base.py b/src/bentoml/_internal/io_descriptors/base.py index 10412a53846..fb79a2056ea 100644 --- a/src/bentoml/_internal/io_descriptors/base.py +++ b/src/bentoml/_internal/io_descriptors/base.py @@ -79,7 +79,8 @@ class IODescriptor(ABC, _OpenAPIMeta, t.Generic[IOType]): if t.TYPE_CHECKING: # Populated by subclasses. Makes pyright happy. - def __init__(self, **kwargs: t.Any) -> None: ... + def __init__(self, **kwargs: t.Any) -> None: + ... __slots__ = ( "_mime_type", @@ -139,7 +140,8 @@ def sample(self, value: IOType) -> None: if t.TYPE_CHECKING: @classmethod - def from_sample(cls, sample: t.Any, **attrs: t.Any) -> t.Self: ... + def from_sample(cls, sample: t.Any, **attrs: t.Any) -> t.Self: + ... @abstractmethod def _from_sample(self, sample: t.Any) -> IOType: diff --git a/src/bentoml/_internal/io_descriptors/multipart.py b/src/bentoml/_internal/io_descriptors/multipart.py index 568281c68b1..a403529f63e 100644 --- a/src/bentoml/_internal/io_descriptors/multipart.py +++ b/src/bentoml/_internal/io_descriptors/multipart.py @@ -327,12 +327,14 @@ async def from_proto(self, field: pb.Multipart) -> dict[str, t.Any]: @t.overload async def _to_proto_impl( self, obj: dict[str, t.Any], *, version: t.Literal["v1"] - ) -> pb.Multipart: ... + ) -> pb.Multipart: + ... @t.overload async def _to_proto_impl( self, obj: dict[str, t.Any], *, version: t.Literal["v1alpha1"] - ) -> pb_v1alpha1.Multipart: ... + ) -> pb_v1alpha1.Multipart: + ... async def _to_proto_impl( self, obj: dict[str, t.Any], *, version: str diff --git a/src/bentoml/_internal/io_descriptors/numpy.py b/src/bentoml/_internal/io_descriptors/numpy.py index b909dcf36bd..02b53b51424 100644 --- a/src/bentoml/_internal/io_descriptors/numpy.py +++ b/src/bentoml/_internal/io_descriptors/numpy.py @@ -65,13 +65,15 @@ @t.overload def dtypepb_to_npdtype_map( version: t.Literal["v1"] = ..., -) -> dict[pb.NDArray.DType.ValueType, ext.NpDTypeLike]: ... +) -> dict[pb.NDArray.DType.ValueType, ext.NpDTypeLike]: + ... @t.overload def dtypepb_to_npdtype_map( version: t.Literal["v1alpha1"] = ..., -) -> dict[pb_v1alpha1.NDArray.DType.ValueType, ext.NpDTypeLike]: ... +) -> dict[pb_v1alpha1.NDArray.DType.ValueType, ext.NpDTypeLike]: + ... @lru_cache(maxsize=2) @@ -95,13 +97,15 @@ def dtypepb_to_npdtype_map( @t.overload def dtypepb_to_fieldpb_map( version: t.Literal["v1"] = ..., -) -> dict[pb.NDArray.DType.ValueType, str]: ... +) -> dict[pb.NDArray.DType.ValueType, str]: + ... @t.overload def dtypepb_to_fieldpb_map( version: t.Literal["v1alpha1"] = ..., -) -> dict[pb_v1alpha1.NDArray.DType.ValueType, str]: ... +) -> dict[pb_v1alpha1.NDArray.DType.ValueType, str]: + ... @lru_cache(maxsize=2) @@ -121,13 +125,15 @@ def fieldpb_to_npdtype_map() -> dict[str, ext.NpDTypeLike]: @t.overload def npdtype_to_dtypepb_map( version: t.Literal["v1"] = ..., -) -> dict[ext.NpDTypeLike, pb.NDArray.DType.ValueType]: ... +) -> dict[ext.NpDTypeLike, pb.NDArray.DType.ValueType]: + ... @t.overload def npdtype_to_dtypepb_map( version: t.Literal["v1alpha1"] = ..., -) -> dict[ext.NpDTypeLike, pb_v1alpha1.NDArray.DType.ValueType]: ... +) -> dict[ext.NpDTypeLike, pb_v1alpha1.NDArray.DType.ValueType]: + ... @lru_cache(maxsize=2) @@ -587,12 +593,14 @@ async def from_proto(self, field: pb.NDArray | bytes) -> ext.NpNDArray: @t.overload async def _to_proto_impl( self, obj: ext.NpNDArray, *, version: t.Literal["v1"] - ) -> pb.NDArray: ... + ) -> pb.NDArray: + ... @t.overload async def _to_proto_impl( self, obj: ext.NpNDArray, *, version: t.Literal["v1alpha1"] - ) -> pb_v1alpha1.NDArray: ... + ) -> pb_v1alpha1.NDArray: + ... async def _to_proto_impl( self, obj: ext.NpNDArray, *, version: str diff --git a/src/bentoml/_internal/io_descriptors/pandas.py b/src/bentoml/_internal/io_descriptors/pandas.py index 7c0c99a32c3..92752bad9f1 100644 --- a/src/bentoml/_internal/io_descriptors/pandas.py +++ b/src/bentoml/_internal/io_descriptors/pandas.py @@ -682,12 +682,14 @@ def process_columns_contents(content: pb.Series) -> dict[str, t.Any]: @t.overload async def _to_proto_impl( self, obj: ext.PdDataFrame, *, version: t.Literal["v1"] - ) -> pb.DataFrame: ... + ) -> pb.DataFrame: + ... @t.overload async def _to_proto_impl( self, obj: ext.PdDataFrame, *, version: t.Literal["v1alpha1"] - ) -> pb_v1alpha1.DataFrame: ... + ) -> pb_v1alpha1.DataFrame: + ... async def _to_proto_impl( self, obj: ext.PdDataFrame, *, version: str @@ -1141,12 +1143,14 @@ async def from_proto(self, field: pb.Series | bytes) -> ext.PdSeries: @t.overload async def _to_proto_impl( self, obj: ext.PdSeries, *, version: t.Literal["v1"] - ) -> pb.Series: ... + ) -> pb.Series: + ... @t.overload async def _to_proto_impl( self, obj: ext.PdSeries, *, version: t.Literal["v1alpha1"] - ) -> pb_v1alpha1.Series: ... + ) -> pb_v1alpha1.Series: + ... async def _to_proto_impl( self, obj: ext.PdSeries, *, version: str diff --git a/src/bentoml/_internal/marshal/dispatcher.py b/src/bentoml/_internal/marshal/dispatcher.py index 1fbda49aa9a..f38ba339d63 100644 --- a/src/bentoml/_internal/marshal/dispatcher.py +++ b/src/bentoml/_internal/marshal/dispatcher.py @@ -143,9 +143,9 @@ def __init__( self.tick_interval = 0.001 self._controller = None - self._queue: collections.deque[Job[T_IN, T_OUT]] = ( - collections.deque() - ) # TODO(bojiang): maxlen + self._queue: collections.deque[ + Job[T_IN, T_OUT] + ] = collections.deque() # TODO(bojiang): maxlen self.get_batch_size = get_batch_size self._sema = shared_sema if shared_sema else NonBlockSema(1) diff --git a/src/bentoml/_internal/models/model.py b/src/bentoml/_internal/models/model.py index 8e1d0d6cb3e..422121c3bd6 100644 --- a/src/bentoml/_internal/models/model.py +++ b/src/bentoml/_internal/models/model.py @@ -639,10 +639,12 @@ def to_dict(self) -> t.Dict[str, t.Any]: return bentoml_cattr.unstructure(self) @overload - def dump(self, stream: io.StringIO) -> io.BytesIO: ... + def dump(self, stream: io.StringIO) -> io.BytesIO: + ... @overload - def dump(self, stream: None = None) -> None: ... + def dump(self, stream: None = None) -> None: + ... def dump(self, stream: io.StringIO | None = None) -> io.BytesIO | None: return yaml.safe_dump(self.to_dict(), stream=stream, sort_keys=False) # type: ignore (bad yaml types) diff --git a/src/bentoml/_internal/monitoring/api.py b/src/bentoml/_internal/monitoring/api.py index 8eaf34fdafb..c8067b8694b 100644 --- a/src/bentoml/_internal/monitoring/api.py +++ b/src/bentoml/_internal/monitoring/api.py @@ -26,7 +26,8 @@ def monitor( name: str | t.Any, monitor_class: DefaultMonitor = ..., monitor_options: dict[str, t.Any] | None = ..., -) -> t.Generator[DefaultMonitor, None, None]: ... +) -> t.Generator[DefaultMonitor, None, None]: + ... @t.overload @@ -35,7 +36,8 @@ def monitor( name: str | t.Any, monitor_class: str = ..., monitor_options: dict[str, t.Any] | None = ..., -) -> t.Generator[MonitorBase[t.Any], None, None]: ... +) -> t.Generator[MonitorBase[t.Any], None, None]: + ... @t.overload @@ -44,7 +46,8 @@ def monitor( name: str | t.Any, monitor_class: None = ..., monitor_options: dict[str, t.Any] | None = ..., -) -> t.Generator[MonitorBase[t.Any], None, None]: ... +) -> t.Generator[MonitorBase[t.Any], None, None]: + ... @contextlib.contextmanager diff --git a/src/bentoml/_internal/monitoring/base.py b/src/bentoml/_internal/monitoring/base.py index d6b1ae2aca4..38a01ebab20 100644 --- a/src/bentoml/_internal/monitoring/base.py +++ b/src/bentoml/_internal/monitoring/base.py @@ -5,12 +5,12 @@ import logging import typing as t -MON_COLUMN_VAR: contextvars.ContextVar["dict[str, dict[str, str]] | None"] = ( - contextvars.ContextVar("MON_COLUMN_VAR", default=None) -) -MON_DATAS_VAR: contextvars.ContextVar["dict[str, collections.deque[t.Any]] | None"] = ( - contextvars.ContextVar("MON_DATAS_VAR", default=None) -) +MON_COLUMN_VAR: contextvars.ContextVar[ + "dict[str, dict[str, str]] | None" +] = contextvars.ContextVar("MON_COLUMN_VAR", default=None) +MON_DATAS_VAR: contextvars.ContextVar[ + "dict[str, collections.deque[t.Any]] | None" +] = contextvars.ContextVar("MON_DATAS_VAR", default=None) DT = t.TypeVar("DT") MT = t.TypeVar("MT", bound="MonitorBase[t.Any]") diff --git a/src/bentoml/_internal/runner/container.py b/src/bentoml/_internal/runner/container.py index d64ef0cacf1..fc1694a1279 100644 --- a/src/bentoml/_internal/runner/container.py +++ b/src/bentoml/_internal/runner/container.py @@ -54,11 +54,13 @@ def create_payload( @classmethod @abc.abstractmethod - def to_payload(cls, batch: BatchType, batch_dim: int) -> Payload: ... + def to_payload(cls, batch: BatchType, batch_dim: int) -> Payload: + ... @classmethod @abc.abstractmethod - def from_payload(cls, payload: Payload) -> BatchType: ... + def from_payload(cls, payload: Payload) -> BatchType: + ... @t.overload @classmethod @@ -67,7 +69,8 @@ def to_triton_payload( inp: tritongrpcclient.InferInput, meta: tritongrpcclient.service_pb2.ModelMetadataResponse.TensorMetadata, _use_http_client: t.Literal[False] = ..., - ) -> tritongrpcclient.InferInput: ... + ) -> tritongrpcclient.InferInput: + ... @t.overload @classmethod @@ -76,7 +79,8 @@ def to_triton_payload( inp: tritonhttpclient.InferInput, meta: dict[str, t.Any], _use_http_client: t.Literal[True] = ..., - ) -> tritongrpcclient.InferInput: ... + ) -> tritongrpcclient.InferInput: + ... @classmethod def to_triton_payload( @@ -127,25 +131,29 @@ def to_triton_http_payload( @abc.abstractmethod def batches_to_batch( cls, batches: t.Sequence[BatchType], batch_dim: int - ) -> tuple[BatchType, list[int]]: ... + ) -> tuple[BatchType, list[int]]: + ... @classmethod @abc.abstractmethod def batch_to_batches( cls, batch: BatchType, indices: t.Sequence[int], batch_dim: int - ) -> list[BatchType]: ... + ) -> list[BatchType]: + ... @classmethod @abc.abstractmethod def batch_to_payloads( cls, batch: BatchType, indices: t.Sequence[int], batch_dim: int - ) -> list[Payload]: ... + ) -> list[Payload]: + ... @classmethod @abc.abstractmethod def from_batch_payloads( cls, payloads: t.Sequence[Payload], batch_dim: int - ) -> tuple[BatchType, list[int]]: ... + ) -> tuple[BatchType, list[int]]: + ... @classmethod def get_batch_size(cls, batch: BatchType, batch_dim: int) -> int: @@ -694,16 +702,16 @@ def register_builtin_containers(): class AutoContainer(DataContainer[t.Any, t.Any]): @classmethod def to_payload(cls, batch: t.Any, batch_dim: int) -> Payload: - container_cls: t.Type[DataContainer[t.Any, t.Any]] = ( - DataContainerRegistry.find_by_batch_type(type(batch)) - ) + container_cls: t.Type[ + DataContainer[t.Any, t.Any] + ] = DataContainerRegistry.find_by_batch_type(type(batch)) return container_cls.to_payload(batch, batch_dim) @classmethod def get_batch_size(cls, batch: Any, batch_dim: int) -> int: - container_cls: t.Type[DataContainer[t.Any, t.Any]] = ( - DataContainerRegistry.find_by_batch_type(type(batch)) - ) + container_cls: t.Type[ + DataContainer[t.Any, t.Any] + ] = DataContainerRegistry.find_by_batch_type(type(batch)) return container_cls.get_batch_size(batch, batch_dim) @classmethod @@ -718,7 +726,8 @@ def to_triton_payload( inp: tritongrpcclient.InferInput, meta: tritongrpcclient.service_pb2.ModelMetadataResponse.TensorMetadata, _use_http_client: t.Literal[False] = ..., - ) -> tritongrpcclient.InferInput: ... + ) -> tritongrpcclient.InferInput: + ... @t.overload @classmethod @@ -727,7 +736,8 @@ def to_triton_payload( inp: tritonhttpclient.InferInput, meta: dict[str, t.Any], _use_http_client: t.Literal[True] = ..., - ) -> tritongrpcclient.InferInput: ... + ) -> tritongrpcclient.InferInput: + ... @classmethod def to_triton_payload( @@ -752,18 +762,18 @@ def to_triton_payload( def batches_to_batch( cls, batches: t.Sequence[BatchType], batch_dim: int = 0 ) -> tuple[BatchType, list[int]]: - container_cls: t.Type[DataContainer[t.Any, t.Any]] = ( - DataContainerRegistry.find_by_batch_type(type(batches[0])) - ) + container_cls: t.Type[ + DataContainer[t.Any, t.Any] + ] = DataContainerRegistry.find_by_batch_type(type(batches[0])) return container_cls.batches_to_batch(batches, batch_dim) @classmethod def batch_to_batches( cls, batch: BatchType, indices: t.Sequence[int], batch_dim: int = 0 ) -> list[BatchType]: - container_cls: t.Type[DataContainer[t.Any, t.Any]] = ( - DataContainerRegistry.find_by_batch_type(type(batch)) - ) + container_cls: t.Type[ + DataContainer[t.Any, t.Any] + ] = DataContainerRegistry.find_by_batch_type(type(batch)) return container_cls.batch_to_batches(batch, indices, batch_dim) @classmethod @@ -773,9 +783,9 @@ def batch_to_payloads( indices: t.Sequence[int], batch_dim: int = 0, ) -> list[Payload]: - container_cls: t.Type[DataContainer[t.Any, t.Any]] = ( - DataContainerRegistry.find_by_batch_type(type(batch)) - ) + container_cls: t.Type[ + DataContainer[t.Any, t.Any] + ] = DataContainerRegistry.find_by_batch_type(type(batch)) return container_cls.batch_to_payloads(batch, indices, batch_dim) @classmethod diff --git a/src/bentoml/_internal/runner/runnable.py b/src/bentoml/_internal/runner/runnable.py index 1ccb1918bc8..403f41cd617 100644 --- a/src/bentoml/_internal/runner/runnable.py +++ b/src/bentoml/_internal/runner/runnable.py @@ -83,7 +83,8 @@ def method( batch_dim: tuple[int, int] | int = 0, input_spec: AnyType | tuple[AnyType, ...] | None = None, output_spec: AnyType | None = None, - ) -> RunnableMethod[T, P, R]: ... + ) -> RunnableMethod[T, P, R]: + ... @overload @staticmethod @@ -94,7 +95,8 @@ def method( batch_dim: tuple[int, int] | int = 0, input_spec: AnyType | tuple[AnyType, ...] | None = None, output_spec: AnyType | None = None, - ) -> t.Callable[[t.Callable[t.Concatenate[T, P], R]], RunnableMethod[T, P, R]]: ... + ) -> t.Callable[[t.Callable[t.Concatenate[T, P], R]], RunnableMethod[T, P, R]]: + ... @staticmethod def method( diff --git a/src/bentoml/_internal/runner/runner.py b/src/bentoml/_internal/runner/runner.py index a9e64e74c97..d392df8eac9 100644 --- a/src/bentoml/_internal/runner/runner.py +++ b/src/bentoml/_internal/runner/runner.py @@ -130,11 +130,11 @@ def __getattr__( ... @t.overload - def __getattr__( - self, item: t.LiteralString - ) -> RunnerMethod[t.Any, P, t.Any]: ... + def __getattr__(self, item: t.LiteralString) -> RunnerMethod[t.Any, P, t.Any]: + ... - def __getattr__(self, item: str) -> t.Any: ... + def __getattr__(self, item: str) -> t.Any: + ... runner_methods: list[RunnerMethod[t.Any, t.Any, t.Any]] scheduling_strategy: type[Strategy] diff --git a/src/bentoml/_internal/runner/runner_handle/__init__.py b/src/bentoml/_internal/runner/runner_handle/__init__.py index fe9df40e915..828ae336b6b 100644 --- a/src/bentoml/_internal/runner/runner_handle/__init__.py +++ b/src/bentoml/_internal/runner/runner_handle/__init__.py @@ -22,7 +22,8 @@ class RunnerHandle(ABC): @abstractmethod - def __init__(self, runner: AbstractRunner) -> None: ... + def __init__(self, runner: AbstractRunner) -> None: + ... @abstractmethod async def is_ready(self, timeout: int) -> bool: @@ -34,7 +35,8 @@ def run_method( __bentoml_method: RunnerMethod[t.Any, P, R], *args: P.args, **kwargs: P.kwargs, - ) -> R: ... + ) -> R: + ... @abstractmethod async def async_run_method( @@ -42,7 +44,8 @@ async def async_run_method( __bentoml_method: RunnerMethod[t.Any, P, R], *args: P.args, **kwargs: P.kwargs, - ) -> R: ... + ) -> R: + ... @abstractmethod def async_stream_method( @@ -50,7 +53,8 @@ def async_stream_method( __bentoml_method: RunnerMethod[t.Any, P, R], *args: P.args, **kwargs: P.kwargs, - ) -> t.AsyncGenerator[R, None]: ... + ) -> t.AsyncGenerator[R, None]: + ... class DummyRunnerHandle(RunnerHandle): diff --git a/src/bentoml/_internal/runner/strategy.py b/src/bentoml/_internal/runner/strategy.py index 7d44278af92..e253bafadec 100644 --- a/src/bentoml/_internal/runner/strategy.py +++ b/src/bentoml/_internal/runner/strategy.py @@ -22,7 +22,8 @@ def get_worker_count( runnable_class: type[Runnable], resource_request: dict[str, t.Any] | None, workers_per_resource: int | float, - ) -> int: ... + ) -> int: + ... @classmethod @abc.abstractmethod diff --git a/src/bentoml/_internal/server/base_app.py b/src/bentoml/_internal/server/base_app.py index ff254d0da5c..aaf19cc9f70 100644 --- a/src/bentoml/_internal/server/base_app.py +++ b/src/bentoml/_internal/server/base_app.py @@ -35,7 +35,8 @@ def __init__( @property @abc.abstractmethod - def name(self) -> str: ... + def name(self) -> str: + ... @property def on_startup(self) -> list[LifecycleHook]: diff --git a/src/bentoml/_internal/service/service.py b/src/bentoml/_internal/service/service.py index c3bc14b8602..c41dfed797b 100644 --- a/src/bentoml/_internal/service/service.py +++ b/src/bentoml/_internal/service/service.py @@ -98,9 +98,9 @@ class Service: mount_apps: t.List[t.Tuple[ext.ASGIApp, str, str]] = attr.field( init=False, factory=list ) - middlewares: t.List[t.Tuple[t.Type[ext.AsgiMiddleware], t.Dict[str, t.Any]]] = ( - attr.field(init=False, factory=list) - ) + middlewares: t.List[ + t.Tuple[t.Type[ext.AsgiMiddleware], t.Dict[str, t.Any]] + ] = attr.field(init=False, factory=list) # gRPC related mount_servicers: list[tuple[ServicerClass, AddServicerFn, list[str]]] = attr.field( diff --git a/src/bentoml/_internal/utils/__init__.py b/src/bentoml/_internal/utils/__init__.py index c127d285a2b..87ddbc133f4 100644 --- a/src/bentoml/_internal/utils/__init__.py +++ b/src/bentoml/_internal/utils/__init__.py @@ -115,11 +115,13 @@ def add_experimental_docstring(f: t.Callable[P, t.Any]) -> t.Callable[P, t.Any]: @overload -def first_not_none(*args: T | None, default: T) -> T: ... +def first_not_none(*args: T | None, default: T) -> T: + ... @overload -def first_not_none(*args: T | None) -> T | None: ... +def first_not_none(*args: T | None) -> T | None: + ... def first_not_none(*args: T | None, default: None | T = None) -> T | None: diff --git a/src/bentoml/container.py b/src/bentoml/container.py index 00769a5f80b..cffbe1cebc0 100644 --- a/src/bentoml/container.py +++ b/src/bentoml/container.py @@ -61,7 +61,8 @@ def build( ssh: str | ArgType = ..., target: str | ArgType = ..., **kwargs: t.Any, -) -> t.Any: ... +) -> t.Any: + ... @t.overload @@ -87,7 +88,8 @@ def build( metadata_file: PathType | None = ..., opt: tuple[str, ...] | dict[str, str | tuple[str, ...]] | None = ..., **kwargs: t.Any, -) -> t.Any: ... +) -> t.Any: + ... @t.overload @@ -130,7 +132,8 @@ def build( target: str | None = ..., ulimit: str | dict[str, tuple[int, int]] | ArgType = ..., **kwargs: t.Any, -) -> t.Any: ... +) -> t.Any: + ... @t.overload @@ -174,7 +177,8 @@ def build( snapshotter: str | None = ..., storage_driver: str | None = ..., **kwargs: t.Any, -) -> t.Any: ... +) -> t.Any: + ... @t.overload @@ -273,7 +277,8 @@ def build( variant: str | None = ..., volume: str | tuple[str, str, str] | None = ..., **kwargs: t.Any, -) -> t.Any: ... +) -> t.Any: + ... @t.overload @@ -355,7 +360,8 @@ def build( variant: str | None = ..., volume: str | tuple[str, str, str] | None = ..., **kwargs: t.Any, -) -> t.Any: ... +) -> t.Any: + ... @inject diff --git a/src/bentoml/deployment.py b/src/bentoml/deployment.py index 4906cd7ed29..ddbaf6a39af 100644 --- a/src/bentoml/deployment.py +++ b/src/bentoml/deployment.py @@ -39,7 +39,8 @@ def create( strategy: str | None = ..., envs: t.List[EnvItemSchema] | t.List[dict[str, t.Any]] | None = ..., extras: dict[str, t.Any] | None = ..., -) -> DeploymentInfo: ... +) -> DeploymentInfo: + ... @t.overload @@ -51,7 +52,8 @@ def create( *, bento: Tag | str | None = ..., config_file: str | None = ..., -) -> DeploymentInfo: ... +) -> DeploymentInfo: + ... @t.overload @@ -63,7 +65,8 @@ def create( *, bento: Tag | str | None = ..., config_dict: dict[str, t.Any] | None = ..., -) -> DeploymentInfo: ... +) -> DeploymentInfo: + ... @inject @@ -136,7 +139,8 @@ def update( strategy: str | None = ..., envs: t.List[EnvItemSchema] | t.List[dict[str, t.Any]] | None = ..., extras: dict[str, t.Any] | None = ..., -) -> DeploymentInfo: ... +) -> DeploymentInfo: + ... @t.overload @@ -149,7 +153,8 @@ def update( *, bento: Tag | str | None = ..., config_file: str | None = ..., -) -> DeploymentInfo: ... +) -> DeploymentInfo: + ... @t.overload @@ -162,7 +167,8 @@ def update( *, bento: Tag | str | None = ..., config_dict: dict[str, t.Any] | None = ..., -) -> DeploymentInfo: ... +) -> DeploymentInfo: + ... @inject @@ -235,7 +241,8 @@ def apply( *, bento: t.Optional[t.Union[Tag, str]] = ..., config_dict: t.Optional[dict[str, t.Any]] = ..., -) -> DeploymentInfo: ... +) -> DeploymentInfo: + ... @t.overload @@ -248,7 +255,8 @@ def apply( *, bento: t.Optional[t.Union[Tag, str]] = ..., config_file: t.Optional[str] = ..., -) -> DeploymentInfo: ... +) -> DeploymentInfo: + ... @inject diff --git a/src/bentoml/models.py b/src/bentoml/models.py index 75ad5ccffeb..06006cbf313 100644 --- a/src/bentoml/models.py +++ b/src/bentoml/models.py @@ -246,7 +246,8 @@ class CreateKwargs(t.TypedDict): @contextmanager def _create( name: Tag | str, /, **attrs: t.Unpack[CreateKwargs] -) -> t.Generator[Model, None, None]: ... +) -> t.Generator[Model, None, None]: + ... @t.overload @@ -264,7 +265,8 @@ def _create( metadata: dict[str, t.Any] | None = ..., context: ModelContext, _model_store: ModelStore = ..., -) -> t.Generator[Model, None, None]: ... +) -> t.Generator[Model, None, None]: + ... @inject diff --git a/src/bentoml/triton.py b/src/bentoml/triton.py index 9968cbf02c7..5e861116786 100644 --- a/src/bentoml/triton.py +++ b/src/bentoml/triton.py @@ -203,14 +203,16 @@ def __getattr__(self, item: t.Literal["__attrs_init__"]) -> t.Callable[..., None @t.overload def __getattr__( self, item: _ClientMethod - ) -> t.Callable[..., t.Coroutine[t.Any, t.Any, t.Any]]: ... + ) -> t.Callable[..., t.Coroutine[t.Any, t.Any, t.Any]]: + ... @t.overload def __getattr__( self, item: _ModelName ) -> _RunnerMethod[ t.Any, _P, _tritongrpcclient.InferResult | _tritonhttpclient.InferResult - ]: ... + ]: + ... def __getattr__(self, item: str) -> t.Any: from ._internal.runner.runner_handle.remote import TritonRunnerHandle diff --git a/src/bentoml_cli/utils.py b/src/bentoml_cli/utils.py index 9321f530ca4..2efce086ad8 100644 --- a/src/bentoml_cli/utils.py +++ b/src/bentoml_cli/utils.py @@ -33,7 +33,8 @@ class ClickFunctionWrapper(t.Protocol[P]): def __call__( # pylint: disable=no-method-argument *args: P.args, **kwargs: P.kwargs, - ) -> F[P]: ... + ) -> F[P]: + ... WrappedCLI = t.Callable[P, ClickFunctionWrapper[P]] @@ -127,11 +128,13 @@ def validate_docker_tag( @t.overload -def normalize_none_type(value: t.Mapping[str, t.Any]) -> t.Mapping[str, t.Any]: ... +def normalize_none_type(value: t.Mapping[str, t.Any]) -> t.Mapping[str, t.Any]: + ... @t.overload -def normalize_none_type(value: ClickParamType) -> ClickParamType: ... +def normalize_none_type(value: ClickParamType) -> ClickParamType: + ... def normalize_none_type( diff --git a/typings/fs/opener/registry.pyi b/typings/fs/opener/registry.pyi index bfb53ddd0b5..78786e93da7 100644 --- a/typings/fs/opener/registry.pyi +++ b/typings/fs/opener/registry.pyi @@ -11,8 +11,7 @@ from typing import Union from ..base import FS from .base import Opener -if typing.TYPE_CHECKING: - ... +if typing.TYPE_CHECKING: ... class Registry: def __init__(self, default_opener: Text = ..., load_extern: bool = ...) -> None: ... diff --git a/typings/fs/permissions.pyi b/typings/fs/permissions.pyi index c1c7777c265..b91b6a2c9a6 100644 --- a/typings/fs/permissions.pyi +++ b/typings/fs/permissions.pyi @@ -8,8 +8,7 @@ from typing import Tuple from typing import Type from typing import Union -if typing.TYPE_CHECKING: - ... +if typing.TYPE_CHECKING: ... def make_mode(init: Union[int, Iterable[Text], None]) -> int: ... diff --git a/typings/yaml/representer.pyi b/typings/yaml/representer.pyi index 0d0a295ae0a..99fb849ee93 100644 --- a/typings/yaml/representer.pyi +++ b/typings/yaml/representer.pyi @@ -74,8 +74,7 @@ class SafeRepresenter(BaseRepresenter): def represent_none(self, data: NoneType) -> ScalarNode: ... def represent_str(self, data: str) -> ScalarNode: ... - if sys.version_info < (3, 0): - ... + if sys.version_info < (3, 0): ... def represent_binary(self, data: bytes) -> ScalarNode: ... def represent_bool(self, data: bool) -> ScalarNode: ... @@ -94,8 +93,7 @@ class SafeRepresenter(BaseRepresenter): def represent_undefined(self, data: Any) -> NoReturn: ... class Representer(SafeRepresenter): - if sys.version_info < (3, 0): - ... + if sys.version_info < (3, 0): ... def represent_complex(self, data: complex) -> ScalarNode: ... def represent_tuple(self, data: Iterable[Any]) -> SequenceNode: ...