Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added easy mypy fixes #255

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- macos-latest
- macos-12
- windows-latest
python:
- "3.7"
Expand Down
2 changes: 1 addition & 1 deletion src/cleanvision/dataset/hf_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __len__(self) -> int:

def __getitem__(self, item: Union[int, str]) -> Optional[Image.Image]:
try:
image = self._data[item][self._image_key]
image: Image.Image = self._data[item][self._image_key]
return image
except Exception as e:
print(f"Could not load image at index: {item}\n", e)
Expand Down
4 changes: 3 additions & 1 deletion src/cleanvision/dataset/torch_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from cleanvision.dataset.base_dataset import Dataset


if TYPE_CHECKING: # pragma: no cover
from torchvision.datasets.vision import VisionDataset

Expand All @@ -26,7 +27,8 @@ def __len__(self) -> int:
return len(self._data)

def __getitem__(self, item: Union[int, str]) -> Image.Image:
return self._data[item][self._image_idx]
image: Image.Image = self._data[item][self._image_idx]
return image

def get_name(self, index: Union[int, str]) -> str:
return f"idx: {index}"
Expand Down
8 changes: 4 additions & 4 deletions src/cleanvision/issue_managers/image_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def mark_issue(


def calc_avg_brightness(image: Image) -> float:
stat = ImageStat.Stat(image)
stat = ImageStat.Stat(image) # type:ignore
try:
red, green, blue = stat.mean
except ValueError:
Expand Down Expand Up @@ -197,7 +197,7 @@ def get_scores(


def calc_entropy(image: Image) -> float:
entropy = image.entropy()
entropy = image.entropy() # type:ignore
assert isinstance(
entropy, float
) # PIL does not have type ann stub so need to assert function return
Expand Down Expand Up @@ -235,7 +235,7 @@ def get_scores(

def calc_blurriness(gray_image: Image) -> float:
edges = get_edges(gray_image)
blurriness = ImageStat.Stat(edges).var[0]
blurriness = ImageStat.Stat(edges).var[0] # type:ignore
return np.sqrt(blurriness) # type:ignore


Expand Down Expand Up @@ -289,7 +289,7 @@ def get_scores(


def get_edges(gray_image: Image) -> Image:
edges = gray_image.filter(ImageFilter.FIND_EDGES)
edges: Image = gray_image.filter(ImageFilter.FIND_EDGES) # type:ignore
return edges


Expand Down
Loading