Skip to content

Commit

Permalink
Fix mypy errors (#1486)
Browse files Browse the repository at this point in the history
* Fix mypy errors

* Move linters ci to single test
  • Loading branch information
Dipet authored Sep 30, 2023
1 parent e3b47b3 commit 69be4e7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 38 deletions.
41 changes: 20 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,19 @@ jobs:
run: pip install torch==2.0.1 torchvision==0.15.2
- name: Install dependencies
run: pip install .[tests]
- name: Install linters
run: >
pip install
flake8==5.0.3
flake8-docstrings==1.6.0
isort==5.11.5
mypy==0.991
types-PyYAML
types-setuptools
types-pkg-resources
- name: Cleanup the build directory
uses: JesseTG/[email protected]
with:
path: build
- name: Run PyTest
run: pytest
- name: Run Flake8
run: flake8
- name: Run mypy
run: mypy .
- name: Run isort
run: isort --profile black albumentations

check_code_formatting:
name: Check code formatting with Black
check_code_formatting_types:
name: Check code formatting with Black, isort, mypy, flake8
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: ["3.11"]
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -75,10 +59,25 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install Black
run: pip install black==22.6.0
- name: Install linters
run: >
pip install
flake8==5.0.3
flake8-docstrings==1.6.0
isort==5.11.5
mypy==0.991
types-PyYAML
types-setuptools
types-pkg-resources
black==22.6.0
- name: Run Black
run: black --config=black.toml --check .
- name: Run Flake8
run: flake8
- name: Run mypy
run: mypy .
- name: Run isort
run: isort --profile black albumentations

check_transforms_docs:
name: Check that transforms docs are not outdated
Expand Down
1 change: 0 additions & 1 deletion albumentations/augmentations/crops/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def __init__(
always_apply=False,
p=1.0,
):

super(RandomResizedCrop, self).__init__(
height=height, width=width, interpolation=interpolation, always_apply=always_apply, p=p
)
Expand Down
4 changes: 2 additions & 2 deletions albumentations/augmentations/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def add_rain(

image = img.copy()

for (rain_drop_x0, rain_drop_y0) in rain_drops:
for rain_drop_x0, rain_drop_y0 in rain_drops:
rain_drop_x1 = rain_drop_x0 + slant
rain_drop_y1 = rain_drop_y0 + drop_length

Expand Down Expand Up @@ -698,7 +698,7 @@ def add_sun_flare(img, flare_center_x, flare_center_y, src_radius, src_color, ci
overlay = img.copy()
output = img.copy()

for (alpha, (x, y), rad3, (r_color, g_color, b_color)) in circles:
for alpha, (x, y), rad3, (r_color, g_color, b_color) in circles:
cv2.circle(overlay, (x, y), rad3, (r_color, g_color, b_color), -1)

cv2.addWeighted(overlay, alpha, output, 1 - alpha, 0, output)
Expand Down
4 changes: 3 additions & 1 deletion albumentations/augmentations/geometric/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,9 @@ def optical_distortion(
camera_matrix = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]], dtype=np.float32)

distortion = np.array([k, k, 0, 0, 0], dtype=np.float32)
map1, map2 = cv2.initUndistortRectifyMap(camera_matrix, distortion, None, None, (width, height), cv2.CV_32FC1)
map1, map2 = cv2.initUndistortRectifyMap(
camera_matrix, distortion, None, None, (width, height), cv2.CV_32FC1 # type: ignore[attr-defined]
)
return cv2.remap(img, map1, map2, interpolation=interpolation, borderMode=border_mode, borderValue=value)


Expand Down
1 change: 0 additions & 1 deletion albumentations/augmentations/geometric/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,6 @@ def apply_to_bbox(self, bbox: BoxInternalType, stepsx: Tuple = (), stepsy: Tuple
return bbox_returned

def _normalize(self, h, w, xsteps, ysteps):

# compensate for smaller last steps in source image.
x_step = w // self.num_steps
last_x_step = min(w, ((self.num_steps + 1) * x_step)) - (self.num_steps * x_step)
Expand Down
20 changes: 10 additions & 10 deletions albumentations/augmentations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
}

NPDTYPE_TO_OPENCV_DTYPE = {
np.uint8: cv2.CV_8U,
np.uint16: cv2.CV_16U,
np.int32: cv2.CV_32S,
np.float32: cv2.CV_32F,
np.float64: cv2.CV_64F,
np.dtype("uint8"): cv2.CV_8U,
np.dtype("uint16"): cv2.CV_16U,
np.dtype("int32"): cv2.CV_32S,
np.dtype("float32"): cv2.CV_32F,
np.dtype("float64"): cv2.CV_64F,
np.uint8: cv2.CV_8U, # type: ignore[attr-defined]
np.uint16: cv2.CV_16U, # type: ignore[attr-defined]
np.int32: cv2.CV_32S, # type: ignore[attr-defined]
np.float32: cv2.CV_32F, # type: ignore[attr-defined]
np.float64: cv2.CV_64F, # type: ignore[attr-defined]
np.dtype("uint8"): cv2.CV_8U, # type: ignore[attr-defined]
np.dtype("uint16"): cv2.CV_16U, # type: ignore[attr-defined]
np.dtype("int32"): cv2.CV_32S, # type: ignore[attr-defined]
np.dtype("float32"): cv2.CV_32F, # type: ignore[attr-defined]
np.dtype("float64"): cv2.CV_64F, # type: ignore[attr-defined]
}


Expand Down
1 change: 0 additions & 1 deletion albumentations/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ def __init__(

def __call__(self, *args, force_apply: bool = False, **data) -> typing.Dict[str, typing.Any]:
if force_apply or random.random() < self.p:

image = data["image"]

# Expand mono images to have a single channel
Expand Down
1 change: 0 additions & 1 deletion tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ def test_shift_scale_separate_shift_x_shift_y(image, mask):

@pytest.mark.parametrize(["val_uint8"], [[0], [1], [128], [255]])
def test_glass_blur_float_uint8_diff_less_than_two(val_uint8):

x_uint8 = np.zeros((5, 5)).astype(np.uint8)
x_uint8[2, 2] = val_uint8

Expand Down

0 comments on commit 69be4e7

Please sign in to comment.