Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e49f9ac
Introduce type checking to existing Python files
hayat01sh1da Apr 11, 2026
cadb295
Commit pyproject.toml
hayat01sh1da Apr 11, 2026
5f430a4
Add workflows to GHA configuration for typechecking
hayat01sh1da Apr 11, 2026
f7f6558
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 14, 2026
f81f461
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 22, 2026
658f143
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 22, 2026
58ea567
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 22, 2026
e5d6686
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 23, 2026
461ac4a
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 25, 2026
221c386
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 26, 2026
9da8b03
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 28, 2026
6132cd7
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da Apr 28, 2026
abb4eb1
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da May 2, 2026
d6ad557
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da May 2, 2026
4105e3c
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da May 4, 2026
f72853e
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da May 5, 2026
5d83685
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da May 9, 2026
8644853
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da May 11, 2026
07aacfc
Merge branch 'master' into hayat01sh1da/python/introduce-mypy-typeche…
hayat01sh1da May 12, 2026
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
22 changes: 11 additions & 11 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ jobs:
- name: pytest
working-directory: ./python
run: pytest
# mypy:
# timeout-minutes: 10
# runs-on: ubuntu-latest
# needs: change-detection
# if: needs.change-detection.outputs.python-changes == 'true'
# steps:
# - uses: actions/checkout@v6
# - uses: ./.github/actions/setup-python
# - name: mypy
# working-directory: ./python
# run: mypy .
mypy:
timeout-minutes: 10
runs-on: ubuntu-latest
needs: change-detection
if: needs.change-detection.outputs.python-changes == 'true'
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/setup-python
- name: mypy
working-directory: ./python
run: mypy .
5 changes: 5 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.mypy]
python_version = "3.14"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
12 changes: 6 additions & 6 deletions python/src/basic.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
def return_three_strings(string1, string2, string3):
def return_three_strings(string1: str, string2: str, string3: str) -> str:
return f'string1: {string1}, string2: {string2}, string3: {string3}'


def judge_num_1(num):
def judge_num_1(num: int) -> str:
if num >= 10:
return 'Number is 10 or more.'
else:
return 'Number is less then 10.'


def judge_num_2(num):
def judge_num_2(num: int) -> str:
if num > 25:
return 'Number is more than 25.'
elif num <= 10:
Expand All @@ -18,15 +18,15 @@ def judge_num_2(num):
return 'Number more than 10 and 25 or less.'


def print_remainder(num1, num2):
def print_remainder(num1: int, num2: int) -> int:
return num1 % num2


def print_quotient(num1, num2):
def print_quotient(num1: int, num2: int) -> int:
return num1 % num2


def judge_age(age):
def judge_age(age: int) -> str:
if age >= 40:
return 'Now you must start paying a healthcare insurace tax.'
elif age >= 20:
Expand Down
4 changes: 2 additions & 2 deletions python/src/circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class Circle:
def __init__(self, radius):
def __init__(self, radius: float) -> None:
self.radius = radius

def area(self):
def area(self) -> float:
return self.radius ** 2 * math.pi
16 changes: 11 additions & 5 deletions python/src/container.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
def list_favourite_musicians(musician1, musician2, musician3):
def list_favourite_musicians(
musician1: str,
musician2: str,
musician3: str) -> list[str]:
musicians = [musician1, musician2, musician3]
return musicians


def show_geographical_info(country, latitude, longitude):
def show_geographical_info(
country: str, latitude: float, longitude: float) -> tuple[str, float, float]:
country = (country, latitude, longitude)
return country


def show_self_info(height, occupation, nationality, favourite_colour):
def show_self_info(height: int, occupation: str, nationality: str,
favourite_colour: str) -> dict[str, int | str]:
self_info = {
'height': height,
'occupation': occupation,
Expand All @@ -18,7 +23,7 @@ def show_self_info(height, occupation, nationality, favourite_colour):
return self_info


def get_value():
def get_value() -> int | str:
self_info = {
'height': 171,
'occupation': 'Server-side engineer',
Expand All @@ -30,7 +35,8 @@ def get_value():
return value


def show_favourite_tunes(musician, *tunes):
def show_favourite_tunes(musician: str, *
tunes: str) -> dict[str, tuple[str, ...]]:
tunes = {
musician: tunes
}
Expand Down
2 changes: 1 addition & 1 deletion python/src/cubed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math


def calc_num(num):
def calc_num(num: float) -> float:
return math.pow(num, 3)
6 changes: 3 additions & 3 deletions python/src/file.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import csv


def read_file(file):
def read_file(file: str) -> str:
with open(file, 'r') as f:
return f.read()


def write_file(file):
def write_file(file: str) -> str:
val = input('Input something: ').strip()
with open(file, 'w+') as f:
f.write(val)
f.seek(0)
return f.read()


def write_csv(file, data):
def write_csv(file: str, data: list[list[str]]) -> str:
with open(file, 'w+') as f:
w = csv.writer(f, delimiter=',')
for datum in data:
Expand Down
17 changes: 10 additions & 7 deletions python/src/function.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
def cube():
def cube() -> int:
num = int(input('Input a number: ').strip())
return num ** 3


def return_str(str):
def return_str(str: str) -> str:
return str


def introduce_self(name, lang_in_study, main_lang='Ruby'):
def introduce_self(
name: str,
lang_in_study: str,
main_lang: str = 'Ruby') -> str:
return f'Hi, I am {name} and stdying {lang_in_study} so hard. My main programming language is {main_lang}'


def halve(num):
def halve(num: float) -> float:
return num / 2


def fourfold(num):
def fourfold(num: float) -> float:
return num * 4


def calculate(num):
def calculate(num: float) -> float:
value = halve(num)
return fourfold(value)


def convert_to_float(str):
def convert_to_float(str: str) -> float | str:
try:
return float(str)
except (ValueError):
Expand Down
11 changes: 9 additions & 2 deletions python/src/hexagon.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
class Hexagon:
def __init__(self, s1, s2, s3, s4, s5, s6):
def __init__(
self,
s1: float,
s2: float,
s3: float,
s4: float,
s5: float,
s6: float) -> None:
self.side1 = s1
self.side2 = s2
self.side3 = s3
self.side4 = s4
self.side5 = s5
self.side6 = s6

def calculate_perimeter(self):
def calculate_perimeter(self) -> float:
sides = [
self.side1,
self.side2,
Expand Down
2 changes: 1 addition & 1 deletion python/src/horse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Horse:
def __init__(self, name, age, rider):
def __init__(self, name: str, age: int, rider: str) -> None:
self.name = name
self.age = age
self.rider = rider
2 changes: 1 addition & 1 deletion python/src/is_the_same.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def is_the_same(obj1, obj2):
def is_the_same(obj1: object, obj2: object) -> bool:
return obj1 is obj2
10 changes: 5 additions & 5 deletions python/src/loop.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
def print_tv_dramas(movies):
def print_tv_dramas(movies: list[str]) -> None:
for movie in movies:
print(movie)


def print_nums(nums):
def print_nums(nums: list[int]) -> None:
for i in nums:
print(i)


def print_tv_dramas_with_index(movies):
def print_tv_dramas_with_index(movies: list[str]) -> None:
for i in range(0, len(movies)):
movie = movies[i]
print(f'{i + 1}: {movie}')


def guess_num(val):
def guess_num(val: str) -> None:
nums = [1, 3, 5, 7, 9]
while True:
# val = input('Input a number or \'q\' to quit: ').strip()
Expand All @@ -31,7 +31,7 @@ def guess_num(val):
print('Try it again!')


def matrix(nums1, nums2):
def matrix(nums1: list[int], nums2: list[int]) -> list[int]:
result = []
for num1 in nums1:
for num2 in nums2:
Expand Down
24 changes: 12 additions & 12 deletions python/src/modu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,69 @@
# https://docs.python.org/3/library/statistics.html#statistics.mean


def calc_mean(data):
def calc_mean(data: list[float]) -> float:
return s.mean(data)

# https://docs.python.org/3/library/statistics.html#statistics.fmean


def calc_fmean(data):
def calc_fmean(data: list[float]) -> float:
return s.fmean(data)

# https://docs.python.org/3/library/statistics.html#statistics.geometric_mean


def calc_geometric_mean(data):
def calc_geometric_mean(data: list[float]) -> float:
return s.geometric_mean(data)

# https://docs.python.org/3/library/statistics.html#statistics.harmonic_mean


def calc_harmonic_mean(data):
def calc_harmonic_mean(data: list[float]) -> float:
return s.harmonic_mean(data)

# https://docs.python.org/3/library/statistics.html#statistics.median


def calc_median(data):
def calc_median(data: list[float]) -> float:
return s.median(data)

# https://docs.python.org/3/library/statistics.html#statistics.median_low


def calc_median_low(data):
def calc_median_low(data: list[float]) -> float:
return s.median_low(data)

# https://docs.python.org/3/library/statistics.html#statistics.median_high


def calc_median_high(data):
def calc_median_high(data: list[float]) -> float:
return s.median_high(data)

# https://docs.python.org/3/library/statistics.html#statistics.median_grouped


def calc_median_grouped(data):
def calc_median_grouped(data: list[float]) -> float:
return s.median_grouped(data)

# https://docs.python.org/3/library/statistics.html#statistics.mode


def calc_mode(data):
def calc_mode(data: list[float]) -> float:
return s.mode(data)

# https://docs.python.org/3/library/statistics.html#statistics.multimode


def calc_multimode(data):
def calc_multimode(data: list[float]) -> list[float]:
return s.multimode(data)

# https://docs.python.org/3/library/statistics.html#statistics.quantiles


def calc_quantiles(data):
def calc_quantiles(data: list[float]) -> list[float]:
return s.quantiles(data)


def import_cubed(num):
def import_cubed(num: float) -> float:
return c.calc_num(num)
2 changes: 1 addition & 1 deletion python/src/pet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Pet:
def __init__(self, species, name, age):
def __init__(self, species: str, name: str, age: int) -> None:
self.species = species
self.name = name
self.age = age
4 changes: 2 additions & 2 deletions python/src/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


class Rectangle(Shape):
def __init__(self, v, h):
def __init__(self, v: float, h: float) -> None:
self.vertical = v
self.horizontal = h

def calculate_perimeter(self):
def calculate_perimeter(self) -> float:
return (self.vertical * 2) + (self.horizontal * 2)
2 changes: 1 addition & 1 deletion python/src/rider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Rider:
def __init__(self, name, age):
def __init__(self, name: str, age: int) -> None:
self.name = name
self.age = age
4 changes: 2 additions & 2 deletions python/src/shape.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Shape:
def __init__(self):
def __init__(self) -> None:
pass

def what_am_i(self):
def what_am_i(self) -> str:
return 'I am a shape.'
8 changes: 4 additions & 4 deletions python/src/square.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


class Square(Shape):
square_list = []
square_list: list[float] = []

def __init__(self, s):
def __init__(self, s: float) -> None:
self.side = s
self.square_list.append(self.side)

def calculate_perimeter(self):
def calculate_perimeter(self) -> float:
dimension = self.side * 4
return dimension

def change_size(self, diff):
def change_size(self, diff: float) -> float:
return (self.side + diff) * 4
Loading
Loading