python-modern-pythonlisted
Install: claude install-skill martinffx/atelier
# Modern Python Features
Modern Python 3.10+ language features, type hints, and patterns.
## Type Hints
### Basic Types
```python
def greet(name: str) -> str:
return f"Hello {name}"
age: int = 25
prices: list[float] = [9.99, 19.99]
mapping: dict[str, int] = {"a": 1}
```
### Union Types (Python 3.10+)
```python
# Modern syntax
def process(value: int | str) -> bool:
...
# Optional
def get_user(id: int) -> User | None:
...
# Multiple types
Result = int | str | bool
```
### Generic Types
```python
from typing import TypeVar, Generic
T = TypeVar("T")
class Repository(Generic[T]):
def get(self, id: int) -> T | None:
...
def save(self, entity: T) -> T:
...
user_repo = Repository[User]()
```
### Protocol (Structural Typing)
```python
from typing import Protocol
class Drawable(Protocol):
"""Structural type - any class with draw()"""
def draw(self) -> None:
...
def render(obj: Drawable) -> None:
"""Works with any object that has draw()"""
obj.draw()
```
## Pattern Matching (Python 3.10+)
### Basic Matching
```python
def handle_command(command: str):
match command:
case "start":
start_process()
case "stop":
stop_process()
case "status":
return get_status()
case _:
raise ValueError("Unknown command")
```
### Matching with Values
```python
def handle_http_status(status: int):
match status:
case 200: