Type Hints Are Not Enforced

This function loads a retry count from a config dict:

def get_retry_count(config: dict[str, int]) -> int:
    return config.get("retries", 3)

value = get_retry_count({"retries": "5"})
print(value, type(value))
print(value + 1)

The config was built from parsed JSON, so "retries" holds the string "5", not the int 5. What happens when this runs?

A

It raises a TypeError at the def get_retry_count(...) line itself, because defining a function checks its body against the declared parameter and return types.

B

It prints 5 <class 'str'>, then raises TypeError: can only concatenate str (not "int") to str on the last line. The config: dict[str, int] and -> int annotations are never checked at runtime, they are documentation only, so config.get(...) returns the string unchanged. The error only appears when value + 1 later tries to add a str and an int.

C

It raises TypeError: config['retries'] does not match declared type int as soon as get_retry_count is called, because Python checks dict values against the dict[str, int] annotation before running the function body.

D

It runs to completion and prints 5 <class 'int'>, because Python converts the string "5" to an int automatically whenever an int annotation is nearby.