On this page
  1. typing.cast
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

typing.cast

Prev: typing.Callable | Up: typing | Next: typing.ChainMap
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.cast
Tags: #public #python3 #stdlib #typing


Import

import typing
from typing import cast

Signature & Overview

typing.cast(typ, val)

Cast a value to a type.

Usage

from typing import cast

raw: object = "hello"
text = cast(str, raw)
assert text == "hello"

Gotchas

REPL Inspect

from typing import cast
help(cast)

Linked from

Related notes