[Python] Python equivalent to `as` type assertion in TypeScript [duplicate]

Discussão em 'Python' iniciado por Stack, Fevereiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    In TypeScript you can override type inferences with the as keyword

    const canvas = document.querySelector('canvas') as HTMLCanvasElement;


    Are there similar techniques in Python3.x typing without involving runtime casting? I want to do something like the following:

    class SpecificDict(TypedDict):
    foo: str
    bar: str

    res = request(url).json() as SpecificDict

    Continue reading...

Compartilhe esta Página