Skip to content
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
9 changes: 7 additions & 2 deletions computer_vision/mean_threshold.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import cast

from PIL import Image

"""
Expand All @@ -13,15 +15,18 @@ def mean_threshold(image: Image.Image) -> Image.Image:
height, width = image.size
mean = 0
pixels = image.load()
if pixels is None:
raise ValueError("image does not support pixel access")
for i in range(width):
for j in range(height):
pixel = pixels[j, i]
pixel = cast(int | float, pixels[j, i])
mean += pixel
mean //= width * height

for j in range(width):
for i in range(height):
pixels[i, j] = 255 if pixels[i, j] > mean else 0
pixel = cast(int | float, pixels[i, j])
pixels[i, j] = 255 if pixel > mean else 0
return image


Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,15 @@
# assumptions consistent with the CI job in .github/workflows/ty.yml, where the
# free-threaded 3.15t test venv would otherwise leave several stubs unresolved.
environment.python-version = "3.15"
rules.call-non-callable = "ignore"

Check warning on line 319 in pyproject.toml

View workflow job for this annotation

GitHub Actions / ty

ty (renamed-rule)

pyproject.toml:319:7: renamed-rule: Rule `call-non-callable` has been renamed to `not-callable`
rules.invalid-argument-type = "ignore"
rules.invalid-return-type = "ignore"

Check warning on line 321 in pyproject.toml

View workflow job for this annotation

GitHub Actions / ty

ty (renamed-rule)

pyproject.toml:321:7: renamed-rule: Rule `invalid-return-type` has been renamed to `invalid-explicit-return`
rules.no-matching-overload = "ignore"
rules.not-iterable = "ignore"
rules.not-subscriptable = "ignore"
rules.parameter-already-assigned = "ignore"
rules.unresolved-attribute = "ignore"

Check warning on line 326 in pyproject.toml

View workflow job for this annotation

GitHub Actions / ty

ty (renamed-rule)

pyproject.toml:326:7: renamed-rule: Rule `unresolved-attribute` has been renamed to `missing-attribute`
rules.unresolved-import = "ignore"

Check warning on line 327 in pyproject.toml

View workflow job for this annotation

GitHub Actions / ty

ty (renamed-rule)

pyproject.toml:327:7: renamed-rule: Rule `unresolved-import` has been renamed to `import-not-found`
rules.unsupported-operator = "ignore"

[tool.pytest]
ini_options.addopts = [
Expand Down
1 change: 1 addition & 0 deletions sorts/iterative_merge_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class Comparable(Protocol):
def __lt__(self, other: Any, /) -> bool: ...
def __le__(self, other: Any, /) -> bool: ...


def merge[T: Comparable](input_list: list[T], low: int, mid: int, high: int) -> list[T]:
Expand Down
2 changes: 2 additions & 0 deletions sorts/quick_sort_3_partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class Comparable(Protocol):
def __lt__(self, other: Any, /) -> bool: ...
def __gt__(self, other: Any, /) -> bool: ...
def __ge__(self, other: Any, /) -> bool: ...


def quick_sort_3partition[T: Comparable](
Expand Down
1 change: 1 addition & 0 deletions sorts/recursive_quick_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class Comparable(Protocol):
def __ge__(self, other: Any, /) -> bool: ...
def __gt__(self, other: Any, /) -> bool: ...
def __le__(self, other: Any, /) -> bool: ...


Expand Down
2 changes: 1 addition & 1 deletion web_programming/get_amazon_product_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_amazon_product_data(product: str = "laptop") -> DataFrame:
):
try:
product_title = item.h2.text
product_link = "https://www.amazon.in/" + item.h2.a["href"]
product_link = f"https://www.amazon.in/{item.h2.a['href']}"
product_price = item.find("span", attrs={"class": "a-offscreen"}).text
try:
product_rating = item.find("span", attrs={"class": "a-icon-alt"}).text
Expand Down
Loading