Přeskočit na obsah
_CORE
AI & Agentic Systems Core Informační Systémy Cloud & Platform Engineering Data Platforma & Integrace Security & Compliance QA, Testing & Observability IoT, Automatizace & Robotika Mobile & Digital Banky & Finance Pojišťovnictví Veřejná správa Obrana & Bezpečnost Zdravotnictví Energetika & Utility Telco & Média Průmysl & Výroba Logistika & E-commerce Retail & Loyalty
Reference Technologie Blog Know-how Nástroje
O nás Spolupráce Kariéra
Pojďme to probrat

Python Typing — typové anotace

01. 10. 2025 1 min čtení 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/

Klíčový takeaway

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

pythontypingmypy
Sdílet:

CORE SYSTEMS tým

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