[Python] How do I get Pylance to ignore the possibility of None?

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

  1. Stack

    Stack Membro Participativo

    I love Pylance type checking.

    However, If I have a variable var: Union[None, T], where T implements foo, pylance will throw an error at:

    var.foo() since type None doesn't implement foo.

    Is there any way to resolve this? A way to tell Pylance "This variable is None sometimes but in this case I'm 100% sure it will be assigned

    Continue reading...

Compartilhe esta Página