Skip to content

Commit

Permalink
ci: auto fixes from pre-commit.ci
Browse files Browse the repository at this point in the history
For more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 6, 2024
1 parent 034624b commit 4fc0133
Show file tree
Hide file tree
Showing 37 changed files with 250 additions and 156 deletions.
6 changes: 4 additions & 2 deletions src/_bentoml_impl/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
12 changes: 8 additions & 4 deletions src/_bentoml_impl/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
12 changes: 8 additions & 4 deletions src/_bentoml_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/_bentoml_sdk/service/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions src/_bentoml_sdk/service/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/bentoml/_internal/bento/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
29 changes: 18 additions & 11 deletions src/bentoml/_internal/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/bentoml/_internal/cloud/schemas/modelschemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/bentoml/_internal/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}

Expand Down
3 changes: 2 additions & 1 deletion src/bentoml/_internal/external_typing/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 14 additions & 7 deletions src/bentoml/_internal/external_typing/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,37 @@
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):
"""A collection of SavedModel signatures."""

_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`
Expand Down
12 changes: 6 additions & 6 deletions src/bentoml/_internal/frameworks/diffusers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/bentoml/_internal/frameworks/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions src/bentoml/_internal/io_descriptors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions src/bentoml/_internal/io_descriptors/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4fc0133

Please sign in to comment.