Skip to content
Closed
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
4 changes: 2 additions & 2 deletions computer_vision/mosaic_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def update_image_and_anno(
output_size: tuple[int, int],
scale_range: tuple[float, float],
filter_scale: float = 0.0,
) -> tuple[list, list, str]:
) -> tuple[np.ndarray, list, str]:
"""
- all_img_list <type: list>: list of all images
- all_annos <type: list>: list of all annotations of specific image
Expand All @@ -111,7 +111,7 @@ def update_image_and_anno(
divid_point_y = int(scale_y * output_size[0])

new_anno = []
path_list = []
path_list: list[str] = []
for i, index in enumerate(idxs):
path = all_img_list[index]
path_list.append(path)
Expand Down
7 changes: 5 additions & 2 deletions data_structures/arrays/dynamic_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class DynamicArray:
def __init__(self) -> None:
self.size = 0 # Number of elements in the array
self.capacity = 1 # Initial capacity of the array
self.array = [None] * self.capacity # Create an array with initial capacity
# Create an array with initial capacity
self.array: list[int | None] = [None] * self.capacity

def append(self, item: int) -> None:
"""
Expand Down Expand Up @@ -77,7 +78,9 @@ def get(self, index: int) -> int:
"""
if index < 0 or index >= self.size:
raise IndexError("index out of range")
return self.array[index]
value = self.array[index]
assert value is not None # every filled slot holds an int
return value

def __setitem__(self, index: int, value: int) -> None:
if index < 0 or index >= self.size:
Expand Down
2 changes: 1 addition & 1 deletion graphs/bi_directional_dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def pass_and_relaxation(

def bidirectional_dij(
source: str, destination: str, graph_forward: dict, graph_backward: dict
) -> int:
) -> float:
"""
Bi-directional Dijkstra's algorithm.

Expand Down
14 changes: 9 additions & 5 deletions graphs/hopcroft_karp.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import math
from collections import deque
from typing import cast

_NIL = object()

Expand Down Expand Up @@ -228,11 +229,14 @@ def maximum_matching(self) -> dict[T, T]:
if self.pair_left[left_vertex] is _NIL:
self.depth_first_search(left_vertex)

return {
left_vertex: matched_right # type: ignore[misc]
for left_vertex, matched_right in self.pair_left.items()
if matched_right is not _NIL
}
return cast(
"dict[T, T]",
{
left_vertex: matched_right
for left_vertex, matched_right in self.pair_left.items()
if matched_right is not _NIL
},
)


def hopcroft_karp[T](graph: dict[T, list[T]]) -> dict[T, T]:
Expand Down
7 changes: 6 additions & 1 deletion machine_learning/mfcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"""

import logging
from typing import overload

import numpy as np
import scipy.fftpack as fft
Expand Down Expand Up @@ -289,7 +290,11 @@ def freq_to_mel(freq: float) -> float:
return 2595.0 * np.log10(1.0 + freq / 700.0)


def mel_to_freq(mels: float) -> float:
@overload
def mel_to_freq(mels: float) -> float: ...
@overload
def mel_to_freq(mels: np.ndarray) -> np.ndarray: ...
def mel_to_freq(mels: float | np.ndarray) -> float | np.ndarray:
"""
Convert a frequency in the mel scale to Hertz.

Expand Down
2 changes: 1 addition & 1 deletion networking_flow/ford_fulkerson.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def breadth_first_search(graph: list, source: int, sink: int, parents: list) ->
return visited[sink]


def ford_fulkerson(graph: list, source: int, sink: int) -> int:
def ford_fulkerson(graph: list, source: int, sink: int) -> int | float:
"""
This function returns the maximum flow from source to sink in the given graph.

Expand Down
2 changes: 1 addition & 1 deletion other/dancing_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
# Insert node into column
node.down = col
node.up = col.up
col.up.down = node

Check failure on line 68 in other/dancing_links.py

View workflow job for this annotation

GitHub Actions / ty

ty (invalid-assignment)

other/dancing_links.py:68:17: invalid-assignment: Object of type `DLXNode` is not assignable to attribute `down` of type `ColumnNode`
col.up = node

Check failure on line 69 in other/dancing_links.py

View workflow job for this annotation

GitHub Actions / ty

ty (invalid-assignment)

other/dancing_links.py:69:17: invalid-assignment: Object of type `DLXNode` is not assignable to attribute `up` of type `ColumnNode`
col.size += 1

# Link nodes in the same row
Expand Down Expand Up @@ -106,7 +106,7 @@
col.right.left = col
col.left.right = col

def _choose_column(self) -> ColumnNode:
def _choose_column(self) -> ColumnNode | None:
"""Select the column with the smallest size (heuristic)."""
min_size = float("inf")
chosen = None
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ skip = """\
environment.python-version = "3.15"
rules.call-non-callable = "ignore"
rules.invalid-argument-type = "ignore"
rules.invalid-return-type = "ignore"
rules.no-matching-overload = "ignore"
rules.not-iterable = "ignore"
rules.not-subscriptable = "ignore"
Expand Down
1 change: 1 addition & 0 deletions web_programming/random_anime_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def random_anime_character() -> tuple[str, str, str]:
httpx2.get(URL, headers=headers, timeout=10).text, "html.parser"
)
title = soup.find("meta", attrs={"property": "og:title"}).attrs["content"]
assert isinstance(title, str)
image_url = soup.find("meta", attrs={"property": "og:image"}).attrs["content"]
description = soup.find("p", id="description").get_text()
_, image_extension = os.path.splitext(os.path.basename(image_url))
Expand Down
Loading