Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
18a1fa9
Improve code quality, documentation, and type safety
toddmath May 27, 2026
b0c7051
fix python ide config, remove unused imports
toddmath May 27, 2026
f213544
Added new class example
egges Apr 28, 2025
04b3ae2
Added function examples
egges Apr 29, 2025
807ce57
Added a few examples
egges Apr 25, 2025
e5c7151
Expanded map examples.
egges Apr 25, 2025
94ba8dd
Added first examples.
egges Apr 10, 2025
9c192b9
Added anti-pattern code examples.
egges Apr 17, 2025
21ef389
Added initial abstraction example
egges May 8, 2025
fcbb868
Updated examples.
egges May 8, 2025
7811372
Some cleanup.
egges May 8, 2025
ce84514
WiP on abstraction example
egges May 12, 2025
714fda4
Removed output images. Cleaned up examples and organized them around …
egges May 14, 2025
2d72111
Minor fixes.
egges May 26, 2025
beca4f6
Created SDK design examples.
egges May 27, 2025
e45363b
Minor update to sdk example
egges May 27, 2025
5cbec25
Worked on basic serverless example
egges May 14, 2025
1b78eef
Changed example to use 2nd gen cloud run functions. Cleanup.
egges May 20, 2025
7355d45
Fixed serverless Pulumi example.
egges May 23, 2025
1c55cf1
Added mcp example
egges May 15, 2025
61973a5
Added API example + MCP server that integrates with API
egges May 16, 2025
148eca5
Updated example.
egges May 20, 2025
81fd49f
Added dataclasses examples.
egges May 23, 2025
d090540
Added library examples.
egges Jun 24, 2025
6a4e0d8
Builder pattern example.
egges Jun 17, 2025
64225b3
Updated website. Made dataclass immutable. Added metadata to builder …
egges Jun 18, 2025
f9f4831
Added other library examples.
egges Jun 18, 2025
ffb8127
Fixed type issue in base API model.
egges Jun 25, 2025
63b2dcd
Added standard library code examples.
egges Jul 15, 2025
b89fd1e
Minor cleanup of code examples.
egges Jul 17, 2025
bac34ed
Added code example
egges Jul 15, 2025
bec49bf
Added weather example
egges Jul 8, 2025
5ba29f1
Added testing code examples.
egges Jul 11, 2025
f2ef78d
Updated testtips code example
egges Jul 22, 2025
1bae6e9
Added initial ai design pattern code examples.
egges Jul 28, 2025
1af31f6
Added pydantic ai dependency
egges Jul 28, 2025
f1eebdb
Updated code examples.
egges Aug 7, 2025
4d08d8d
Removed unneccesary environment variable setting.
egges Aug 12, 2025
7262f32
Added singleton code examples.
egges Aug 7, 2025
49ac780
Added pyproject file. Minor cleanup. Added thread-safe example.
egges Aug 12, 2025
a6d1c0d
Added code examples for SOLID video.
egges Jul 30, 2025
b32d88a
Added project code example.
egges Aug 12, 2025
910f9e6
Added Python 3.14 code examples.
egges Sep 11, 2025
f8b0868
Added uv workspaces example
egges Sep 16, 2025
ee335f0
Added registry code example.
egges Sep 3, 2025
8c0cc62
Added context object example.
egges Sep 9, 2025
7f0e3b0
Added DI examples.
egges Oct 8, 2025
bdecb71
Added intermediate version. Renamed files for clarity.
egges Oct 8, 2025
d1c8e31
Added initial code example.
egges Sep 30, 2025
4137a7f
Added get_all_events method
egges Sep 30, 2025
e0de2b7
Updated event example
egges Oct 8, 2025
d2314e6
Added pythonic code example
egges Oct 2, 2025
87279cb
Examples for learning Python fast
egges Oct 8, 2025
0ec8a7d
Added aiGrunn code example
egges Nov 13, 2025
9479108
Added code example.
egges Oct 30, 2025
1074989
Added ttl example
egges Nov 11, 2025
155c1d1
Added threaded example
egges Nov 11, 2025
7192b89
Rough code example.
egges Oct 29, 2025
dd121a5
More work on production code example
egges Oct 30, 2025
c79ad86
Worked on code example
egges Nov 5, 2025
86e5402
Minor improvements
egges Nov 5, 2025
f4fbe30
Fixed slowapi warning
egges Nov 5, 2025
2d75351
More work on code example.
egges Nov 6, 2025
107d314
More code example cleanup.
egges Nov 6, 2025
c02cf4e
Added retry example
egges Nov 10, 2025
adcd8c7
Added one more example
egges Nov 18, 2025
1094f22
Added code example
egges Nov 5, 2025
c2a9cd4
Added code example
egges Nov 27, 2025
78ac372
Minor tweak to simplify rule system.
egges Dec 10, 2025
76234c1
Updated rule factory type definition.
egges Dec 10, 2025
bdd0163
Minor fixes in rules example.
egges Dec 11, 2025
be8ab7e
Added code example.
egges Dec 3, 2025
8010cd9
Various fixes in code example. Added proper before version.
egges Dec 9, 2025
c560005
Added Python features code examples.
egges Dec 2, 2025
b1bb4ef
Fixed issue in contextvars example.
egges Dec 9, 2025
14baa39
Added code example.
egges Nov 27, 2025
62477c1
Worked on cqrs example.
egges Jan 12, 2026
e61f747
Updated code example
egges Jan 22, 2026
204f400
Added ports example.
egges Jan 20, 2026
d24d421
Updated ports & adapters example.
egges Jan 23, 2026
7ddb151
Example cleanup
egges Jan 28, 2026
de21d26
Minor improvements.
egges Jan 28, 2026
5c2c72f
Added code example
egges Jan 22, 2026
aeb546f
Improved Singleton example
egges Jan 23, 2026
242aa18
More example updates.
egges Jan 23, 2026
49599a9
Removed Optional type
egges Jan 23, 2026
2c99968
Improved auto registry example.
egges Jan 27, 2026
3168342
Added value object example.
egges Jan 23, 2026
f19e88e
Added property vs method code example
egges Jan 16, 2026
f1d800b
Added code example.
egges Feb 13, 2026
6ab78a8
Added pyproject file.
egges Feb 13, 2026
0d8e2bc
WiP on state example.
egges Feb 24, 2026
e1b3c82
Simplified state machine types.
egges Feb 26, 2026
a21d051
Added code examples.
egges Feb 13, 2026
664df04
Work in progress on code example.
egges Feb 12, 2026
41c6d9b
Reworked example. Added sample sales csv.
egges Feb 13, 2026
6794ec7
Cleaned up after version.
egges Feb 26, 2026
a2d97a9
Small code cleanup
egges Mar 5, 2026
102b4f6
Added type checking option to settings.
egges Mar 17, 2026
f2b9a40
Added DRY code examples.
egges Mar 18, 2026
0d637c0
Added custom data example
egges Mar 18, 2026
5ec4f35
Added baseline examples.
egges Mar 18, 2026
ec1d33e
Simplified main file
egges Mar 18, 2026
d61238a
Added policy examples.
egges Mar 18, 2026
fbfe9d1
Added code example.
egges Mar 17, 2026
93039e9
Initial god object code example
egges Apr 22, 2026
9558aab
Simplified code example.
egges Apr 23, 2026
84fe027
Added data generation script.
egges Apr 28, 2026
de68821
Added basic webhook examples.
egges Apr 28, 2026
9f8b617
Worked on webhook example.
egges Apr 30, 2026
7b1dc16
Added code example.
egges Apr 28, 2026
4c5cec1
Improve code quality, documentation, and type safety
toddmath May 27, 2026
ec5fc53
Merge branch 'main' into 2026-upstream-changes
toddmath May 27, 2026
1f2fa89
Delete Ruff linting and formatting workflow
toddmath May 27, 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
29 changes: 0 additions & 29 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
name: Python Linting and formatting with Ruff

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}

- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install ruff
- run: |
ruff format
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'Code formatted with Ruff'
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// "python.envFile": "${workspaceFolder}/.env",,
// Test settings
"python.testing.pytestEnabled": true,
// "python.testing.unittestEnabled": false,
// "python.testing.unittestEnabled": false,
"python.testing.cwd": "${workspaceFolder}/tests",
"python.defaultInterpreterPath": "${workspaceFolder}/2025/typescript/lokalise/.venv/bin/python",
// "python.analysis.typeCheckingMode": "off"
}
}
2 changes: 1 addition & 1 deletion 2022/async/after-1/iot/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio
# import asyncio
import random
import string
from typing import Protocol
Expand Down
2 changes: 1 addition & 1 deletion 2022/async/after-2/iot/service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import random
import string
from typing import Any, Awaitable, Protocol
from typing import Protocol

from iot.message import Message, MessageType

Expand Down
19 changes: 7 additions & 12 deletions 2025/go/error_handling.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
def read_and_sum_integers(file_path):
try:
with open(file_path, "r") as file:
sum = 0
with open(file_path, "r", encoding="utf-8") as file:
total = 0
for line in file:
try:
num = int(line.strip())
sum += num
total += num
except ValueError as e:
raise ValueError(
f"Invalid content in file: '{line.strip()}'"
) from e
return sum
return total
except FileNotFoundError as e:
raise FileNotFoundError(f"File not found: {file_path}") from e
except Exception as e:
raise RuntimeError(f"An unexpected error occurred: {e}") from e
except OSError as e:
raise RuntimeError(f"An unexpected OS error occurred: {e}") from e


def main():
Expand All @@ -23,13 +23,8 @@ def main():
try:
total = read_and_sum_integers(file_path)
print(f"Sum of integers: {total}")
except FileNotFoundError as e:
print(f"Error: {e}")
except ValueError as e:
except (FileNotFoundError, ValueError, RuntimeError) as e:
print(f"Error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")


if __name__ == "__main__":
main()
22 changes: 19 additions & 3 deletions 2025/simple/before.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ def take_a_holiday(self, payout: bool) -> None:

@dataclass
class HourlyEmployee(Employee):
"""Represents an hourly employee."""
hourly_rate: float = 50
amount: int = 10


@dataclass
class SalariedEmployee(Employee):
"""Represents a salaried employee who receives a fixed monthly salary payment."""
monthly_salary: float = 5000


Expand All @@ -61,18 +63,23 @@ def __init__(self) -> None:
self.employees: list[Employee] = []

def add_employee(self, employee: Employee) -> None:
"""Add an employee to the company."""
self.employees.append(employee)

def find_managers(self) -> list[Employee]:
"""Find all employees with the role of manager."""
return [e for e in self.employees if e.role == "manager"]

def find_vice_presidents(self) -> list[Employee]:
"""Find all employees with the role of vice-president."""
return [e for e in self.employees if e.role == "vice-president"]

def find_support_staff(self) -> list[Employee]:
"""Find all employees with the role of support."""
return [e for e in self.employees if e.role == "support"]

def pay_employee(self, employee: Employee) -> None:
"""Pay an employee."""
if isinstance(employee, SalariedEmployee):
print(
f"Paying employee {employee.name} a monthly salary of ${employee.monthly_salary}."
Expand Down Expand Up @@ -100,20 +107,30 @@ class Notification(ABC):
def send(self, employee: Employee, message: str) -> None:
pass

@abstractmethod
def is_enabled(self) -> bool:
"""Check if notifications are enabled."""


class EmailNotification(Notification):
"""Email notification implementation."""

def send(self, employee: Employee, message: str) -> None:
print(f"Sending email to {employee.name}: {message}")

def is_enabled(self) -> bool:
return True


class SMSNotification(Notification):
"""SMS notification implementation."""

def send(self, employee: Employee, message: str) -> None:
print(f"Sending SMS to {employee.name}: {message}")

def is_enabled(self) -> bool:
return True


class NotificationFactory:
"""Factory for creating notifications."""
Expand All @@ -122,10 +139,9 @@ class NotificationFactory:
def get_notification(method: str) -> Notification:
if method == "email":
return EmailNotification()
elif method == "sms":
if method == "sms":
return SMSNotification()
else:
raise ValueError("Invalid notification method")
raise ValueError("Invalid notification method")


def main() -> None:
Expand Down
11 changes: 11 additions & 0 deletions 2025/simple/notification_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,28 @@ def take_a_holiday(self, payout: bool) -> None:

@dataclass
class HourlyEmployee(Employee):
"""Represents an hourly employee."""
hourly_rate: float = 50
amount: int = 10


@dataclass
class SalariedEmployee(Employee):
"""Represents a salaried employee who receives a fixed monthly salary payment."""
monthly_salary: float = 5000


@dataclass
class Freelancer(Employee):
"""Represents a freelancer who receives a fixed hourly rate for a fixed amount of hours."""
hourly_rate: float = 50
amount: int = 10
retainer: float = 1000


@dataclass
class Intern(Employee):
"""Represents an intern who receives a fixed monthly salary payment."""
monthly_salary: float = 1000


Expand All @@ -60,18 +64,23 @@ def __init__(self) -> None:
self.employees: list[Employee] = []

def add_employee(self, employee: Employee) -> None:
"""Add an employee to the company."""
self.employees.append(employee)

def find_managers(self) -> list[Employee]:
"""Find all employees with the role of manager."""
return [e for e in self.employees if e.role == "manager"]

def find_vice_presidents(self) -> list[Employee]:
"""Find all employees with the role of vice-president."""
return [e for e in self.employees if e.role == "vice-president"]

def find_support_staff(self) -> list[Employee]:
"""Find all employees with the role of support."""
return [e for e in self.employees if e.role == "support"]

def pay_employee(self, employee: Employee) -> None:
"""Pay an employee."""
if isinstance(employee, SalariedEmployee):
print(
f"Paying employee {employee.name} a monthly salary of ${employee.monthly_salary}."
Expand All @@ -93,10 +102,12 @@ def pay_employee(self, employee: Employee) -> None:


def send_email(employee: Employee, message: str) -> None:
"""Send an email to an employee."""
print(f"Sending email to {employee.name}: {message}")


def send_sms(employee: Employee, message: str) -> None:
"""Send an SMS to an employee."""
print(f"Sending SMS to {employee.name}: {message}")


Expand Down
2 changes: 2 additions & 0 deletions 2025/typehints/generic_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def main() -> None:
items = [100, 200, 300]
discount = 0.2
discounted_items = calculate_discounts(items, discount)
# type: ignore
print(len(discounted_items)) # type issue here
# type: ignore
print(discounted_items[0]) # type issue here


Expand Down
8 changes: 3 additions & 5 deletions 2025/typehints/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[project]
name = "typehints"
version = "0.0.1"
authors = [{name = "ArjanCodes"}]
license = {text = "MIT"}
authors = [{ name = "ArjanCodes" }]
license = { text = "MIT" }
requires-python = ">=3.12"
dependencies = [
"mypy>=1.15.0",
]
dependencies = ["mypy>=1.15.0"]

[tool.pytest.ini_options]
pythonpath = "src"