Python Typing¶
obj.attribute
vs obj["member_of_collection"]
- property is a special kind of attribute
- has either a
__get__
,__set__
or__delete__
spam.eggs
will return the result of__get__
- has either a
TypedDict¶
- new in Python 3.8
- https://adamj.eu/tech/2021/05/10/python-type-hints-how-to-use-typeddict/
from typing import TypedDict
class SalesSummary(TypedDict):
sales: int
year: NotRequired[int]
product_codes: list[str]
def get_sales_summary() -> SalesSummary:
pass
Circular Dependencies with types¶
from __future__ import annotations
from typing import TYPE_CHECKING # false at runtime
if TYPE_CHECKING:
from module_b import B
Last update:
2023-04-24