[Python] Make pyright ok with generic type manipulation

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    The following code which is just the extracted problematic part of a non-useless method, really makes pyright mad, how can I fix that?

    from typing import Type, Optional

    def mymethod[T](in:str, out:Type[T]) -> Optional[T]:
    return out(in)


    Pyright says:

    1 25 error e-f-b Pyright [reportUnusedImport]: Import "Optional" is not accessed
    1 25 note e-f-b Pyright: "Optional" is not accessed
    3 15 error e-f-b Pyright: "(" was not closed
    3 16 error e-f-b Pyright: Position-only parameter separator not allowed as first parameter
    3 16 error e-f-b Pyright: Expected parameter name
    3 28 error e-f-b Pyright [reportInvalidTypeForm]: Type annotation not supported for this statement
    3 35 error e-f-b Pyright: Expected expression
    3 35 error e-f-b Pyright: Statements must be separated by newlines or semicolons
    4 0 note e-f-b Pyright: Code is unreachable
    4 0 error e-f-b Pyright: Statements must be separated by newlines or semicolons
    4 0 error e-f-b Pyright: Expected expression
    4 0 error e-f-b Pyright: Unindent not expected
    4 0 error e-f-b Pyright: Unexpected indentation
    4 4 error e-f-b Pyright: "return" can be used only within a function
    4 11 error e-f-b Pyright [reportUndefinedVariable]: "out" is not defined
    4 14 error e-f-b Pyright: "(" was not closed
    4 15 error e-f-b Pyright: Expected expression

    Continue reading...

Compartilhe esta Página