1. Junior

    Are type hints enforced at runtime in Python?

    No; annotations are metadata read by static analysis tools such as mypy and Pyright, and they do not stop Python from passing a value of a different type at runtime.

    Read the full explanation
  2. Junior

    How do you express a value that may be one of two types or None?

    Use the union syntax X | Y and X | None (since Python 3.10), or Union and Optional from typing in older versions; Optional[X] means X | None and not "an optional parameter".

    Read the full explanation
  3. Mid-level

    What is a Protocol in typing?

    A Protocol describes the required behavior (methods and attributes) and accepts any class that matches it structurally without explicit inheritance; it is a static form of duck typing.

    Read the full explanation
  4. Mid-level

    What is the role of TypeVar and Generic in Python?

    A TypeVar represents an unknown type that must stay the same across parts of a signature, and Generic lets you define a class that preserves the type of what it holds; since Python 3.12 there is also the shorthand syntax def first[T](...) and class Box[T].

    Read the full explanation
  5. Mid-level

    When should you use TypedDict with JSON data?

    TypedDict describes the keys of a dict and the types of its values for static checkers, while the value remains a plain dict at runtime with no validation or conversion.

    Read the full explanation
  6. Junior

    What are Final and Literal used for?

    Final marks a name that should not be reassigned (according to type checkers), and Literal restricts a value to a fixed set of literal values such as "asc" or "desc".

    Read the full explanation
  7. Senior

    When do you use @overload?

    When a single function returns different types depending on the types or values of its arguments; you write several signatures decorated with overload for the type checker, followed by one real implementation with a general signature.

    Read the full explanation
  8. Mid-level

    What is the difference between Any and object in type hints?

    Any disables checking: it accepts any value and allows any operation on it. object also accepts any value but does not allow special operations on it until the type is narrowed.

    Read the full explanation
  9. Senior

    What are TypeGuard and TypeIs for in type narrowing?

    They declare that a boolean predicate function, when it returns True, has narrowed the type of its argument; TypeIs (since Python 3.13) narrows the type in both the True and False branches, while TypeGuard narrows only the True branch.

    Read the full explanation
  10. Senior

    How do you use typing to improve module boundaries without overdoing it?

    Concentrate precise types on public interfaces and system boundaries (public module functions, domain types, protocols), and leave local variables to automatic inference.

    Read the full explanation