Search code examples
pythonpython-typingpyright

Can I disable type errors from third-party packages in Pylance?


Some of the packages I use don't type hint their code, so when I use them, Pylance keeps telling me that the functions I use have partially unknown types, which is a problem I can't fix. Is there a way to disable such errors?


Solution

  • If you're absolutely certain of the type you're getting from the external library and you're sure it's not documented through typeshed either, you can always cast it to signal to the type checker it's to be treated as that type.

    from typing import cast
    from elsewhere import Ham
    
    spam = some_untyped_return()
    ham = cast(Ham, spam)