_str_list(val):
             # Type of ``val`` is narrowed to ``list[str]``.
             print(" ".join(val))
         else:
             # Type of ``val`` remains as ``list[object]``.
             print("Not a list of strings!")

Strict type narrowing is not enforced -- ``TypeB`` need not be a narrower
form of ``TypeA`` (it can even be a wider form) and this may lead to
type-unsafe results.  The main reason is to allow for things like
narrowing ``list[object]`` to ``list[str]`` even though the latter is not
a subtype of the former, since ``list`` is invariant.  The responsibility of
writing type-safe type predicates is left to the user.

``TypeGuard`` also works with type variables.  For more information, see
PEP 647 (User-Defined Type Guards).
rH