[Python] Typehint with kwargs: Pylance reportArgumentType raised on dictionary input

Discussão em 'Python' iniciado por Stack, Junho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have a very simple use case, where pylance does not what I would expect:

    def foo(optional_type_restricted_input: bool = False, **kwargs: int):
    pass

    foo(**{"some_input":5})


    Pylance raises Argument of type "int" cannot be assigned to parameter "type_restricted_input" of type "bool" in function "foo" "int" is not assignable to "bool"

    Also for this case it does not raise that the type of the first arg is wrong:

    def foo(required_type_restricted_input: bool, **kwargs: int):
    pass

    foo(**{"required_type_restricted_input": 5, "some_input":True})


    So, any better idea than adding # type: ignore to all function calls?

    Continue reading...

Compartilhe esta Página