Skip to content

Commit 32aca72

Browse files
authored
refactor: TYPE_CHECKING conventions for pylint + removal of mypy (bentoml#2034)
1 parent 9bc70b8 commit 32aca72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+136
-165
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ jobs:
5858
# TODO: after fix all pylint errors under bentoml uses `make ci-lint` instead
5959
run: make ci-flake8
6060
- name: Type check
61-
# TODO: after fix all types errors uses `make ci-types` instead
6261
run: make ci-pyright
6362

6463
documentation_spelling_check:

Makefile

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
SHELL := /bin/bash
12
.DEFAULT_GOAL := help
23

34
GIT_ROOT ?= $(shell git rev-parse --show-toplevel)
@@ -17,25 +18,10 @@ endif
1718
CMD := docker run $(CNTR_ARGS)
1819
TTY := docker run -t $(CNTR_ARGS)
1920

20-
check_defined = \
21-
$(strip $(foreach 1,$1, \
22-
$(call __check_defined,$1,$(strip $(value 2)))))
23-
__check_defined = \
24-
$(if $(value $1),, \
25-
$(error Undefined $1$(if $2, ($2))$(if $(value @), \
26-
required by target `$@`)))
27-
2821
__style_src := $(wildcard $(GIT_ROOT)/scripts/ci/style/*.sh)
2922
__style_name := ${__style_src:_check.sh=}
3023
tools := $(foreach t, $(__style_name), ci-$(shell basename $(t)))
3124

32-
check-defined-% : __check_defined_FORCE
33-
$(eval $@_target := $(subst check-defined-, ,$@))
34-
@:$(call check_defined, $*, $@_target)
35-
36-
.PHONY : __check_defined_FORCE
37-
__check_defined_FORCE:
38-
3925
help: ## Show all Makefile targets
4026
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'
4127

@@ -57,14 +43,13 @@ format: pull-checker-img ## Running code formatter: black and isort
5743
$(CMD) ./scripts/tools/formatter.sh
5844
lint: pull-checker-img ## Running lint checker: flake8 and pylint
5945
$(CMD) ./scripts/tools/linter.sh
60-
type: pull-checker-img ## Running type checker: mypy and pyright
46+
type: pull-checker-img ## Running type checker: pyright
6147
$(CMD) ./scripts/tools/type_checker.sh
6248

63-
ci-all: $(tools) ## Running codestyle in CI: black, isort, flake8, pylint, mypy, pyright
49+
ci-all: $(tools) ## Running codestyle in CI: black, isort, flake8, pylint, pyright
6450

6551
ci-%: chore
6652
$(eval style := $(subst ci-, ,$@))
67-
$(eval SHELL :=/bin/bash)
6853
$(CMD) ./scripts/ci/style/$(style)_check.sh
6954

7055
.PHONY: ci-format
@@ -74,21 +59,19 @@ ci-format: ci-black ci-isort ## Running format check in CI: black, isort
7459
ci-lint: ci-flake8 ci-pylint ## Running lint check in CI: flake8, pylint
7560

7661
.PHONY: ci-type
77-
ci-type: ci-mypy ci-pyright ## Running type check in CI: mypy, pyright
62+
ci-type: ci-pyright ## Running type check in CI: pyright
7863

7964
tests-%:
8065
$(eval type :=$(subst tests-, , $@))
8166
$(eval RUN_ARGS:=$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
8267
$(eval __positional:=$(foreach t, $(RUN_ARGS), --$(t)))
83-
$(eval SHELL :=/bin/bash)
8468
ifeq ($(USE_POETRY),true)
8569
./scripts/ci/run_tests.sh -v --use-poetry $(type) $(__positional)
8670
else
8771
./scripts/ci/run_tests.sh -v $(type) $(__positional)
8872
endif
8973

9074

91-
9275
ifeq ($(USE_POETRY),true)
9376
install-local: ## Install BentoML with poetry
9477
@./scripts/init.sh
@@ -139,3 +122,17 @@ endif
139122

140123
hooks: ## Install pre-defined hooks
141124
@./scripts/install_hooks.sh
125+
126+
check_defined = \
127+
$(strip $(foreach 1,$1, \
128+
$(call __check_defined,$1,$(strip $(value 2)))))
129+
__check_defined = \
130+
$(if $(value $1),, \
131+
$(error Undefined $1$(if $2, ($2))$(if $(value @), \
132+
required by target `$@`)))
133+
check-defined-% : __check_defined_FORCE
134+
$(eval $@_target := $(subst check-defined-, ,$@))
135+
@:$(call check_defined, $*, $@_target)
136+
137+
.PHONY : __check_defined_FORCE
138+
__check_defined_FORCE:

bentoml/_internal/bento/bento.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import typing as t
44
from datetime import datetime, timezone
5+
from typing import TYPE_CHECKING
56

67
import attr
78
import fs
@@ -22,7 +23,7 @@
2223
from ..utils import cached_property
2324
from .env import BentoEnv
2425

25-
if t.TYPE_CHECKING:
26+
if TYPE_CHECKING: # pragma: no cover
2627
from ..models.store import ModelInfo, ModelStore
2728
from ..service import Service
2829
from ..service.inference_api import InferenceAPI

bentoml/_internal/bento/pip_pkg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import zipfile
88
import zipimport
99
from collections import defaultdict
10+
from typing import TYPE_CHECKING
1011

1112
import importlib_metadata
1213
from packaging.requirements import Requirement
1314

14-
if t.TYPE_CHECKING:
15+
if TYPE_CHECKING: # pragma: no cover
1516
from ..service import Service
1617

1718
EPP_NO_ERROR = 0

bentoml/_internal/configuration/containers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ..utils import get_free_port, validate_or_create_dir
1414
from . import expand_env_var
1515

16-
if TYPE_CHECKING:
16+
if TYPE_CHECKING: # pragma: no cover
1717
from pyarrow._plasma import PlasmaClient
1818

1919
from ..server.metrics.prometheus import PrometheusClient

bentoml/_internal/io_descriptors/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import io
22
import sys
33
import typing as t
4+
from typing import TYPE_CHECKING
45
from urllib.parse import quote
56

67
from multipart.multipart import parse_options_header
@@ -11,8 +12,7 @@
1112
from ..utils import LazyLoader
1213
from .base import IODescriptor
1314

14-
if t.TYPE_CHECKING: # pragma: no cover
15-
# pylint: disable=unused-import
15+
if TYPE_CHECKING: # pragma: no cover
1616
import numpy as np
1717
import PIL
1818
import PIL.Image

bentoml/_internal/io_descriptors/json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dataclasses
22
import json
33
import typing as t
4+
from typing import TYPE_CHECKING
45

56
from starlette.requests import Request
67
from starlette.responses import Response
@@ -9,7 +10,7 @@
910
from ..utils.lazy_loader import LazyLoader
1011
from .base import IODescriptor
1112

12-
if t.TYPE_CHECKING: # pragma: no cover
13+
if TYPE_CHECKING: # pragma: no cover
1314
import numpy as np
1415
import pandas as pd
1516
import pydantic

bentoml/_internal/io_descriptors/multipart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import typing as t
2+
from typing import TYPE_CHECKING
23

34
from multipart.multipart import parse_options_header
45
from starlette.requests import Request
@@ -11,8 +12,7 @@
1112
)
1213
from .base import IODescriptor
1314

14-
if t.TYPE_CHECKING: # pragma: no cover
15-
# pylint: disable=unused-import
15+
if TYPE_CHECKING: # pragma: no cover
1616
import numpy as np # noqa
1717

1818
from ..types import FileLike # noqa

bentoml/_internal/io_descriptors/numpy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import logging
33
import typing as t
4+
from typing import TYPE_CHECKING
45

56
from starlette.requests import Request
67
from starlette.responses import Response
@@ -10,7 +11,7 @@
1011
from .base import IODescriptor
1112
from .json import MIME_TYPE_JSON
1213

13-
if t.TYPE_CHECKING: # pragma: no cover
14+
if TYPE_CHECKING: # pragma: no cover
1415
import numpy as np
1516
else:
1617
np = LazyLoader("np", globals(), "numpy")

bentoml/_internal/io_descriptors/pandas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import typing as t
3+
from typing import TYPE_CHECKING
34

45
from starlette.requests import Request
56
from starlette.responses import Response
@@ -10,7 +11,7 @@
1011
from .base import IODescriptor
1112
from .json import MIME_TYPE_JSON
1213

13-
if t.TYPE_CHECKING: # pragma: no cover
14+
if TYPE_CHECKING: # pragma: no cover
1415
import pandas as pd
1516
else:
1617
pd = LazyLoader("pd", globals(), "pandas")

0 commit comments

Comments
 (0)