_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Python Typing — typové anotace

04. 11. 2025 1 min read intermediate

Type hints zachytí chyby před spuštěním, zlepší IDE autocomplete a slouží jako dokumentace.

Základní typy

from typing import Optional def greet(name: str, times: int = 1) -> str: return f”Hello {name}! ” * times def find_user(user_id: int) -> Optional[dict]: … # Může vrátit None

Python 3.10+

def process(data: str | None) -> list[int]: …

Generics a Protocol

from typing import TypeVar, Protocol T = TypeVar(‘T’) def first(items: list[T]) -> T: return items[0] class Renderable(Protocol): def render(self) -> str: … def display(item: Renderable) -> None: print(item.render())

mypy

pyproject.toml

[tool.mypy] strict = true warn_return_any = true

Spuštění

mypy src/

Key Takeaway

Type hints všude + mypy –strict. Zachytí chyby před runtime, zlepší DX.

pythontypingmypy
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.