Home > front end >  Ignoring a specific undefined variable with pyright
Ignoring a specific undefined variable with pyright

Time:07-04

When writing custom SaltStack modules/states using VScode and linting with pyright, I get the following error all over the place:

"__salt__" is not defined

It's not a killer, because I can put the following on the end of every line that references it:

# pyright: ignore[reportUndefinedVariable]

But what I would rather do is tell my project that __salt__ is a known variable, and don't report on that variable.

Is this possible?

CodePudding user response:

I eventually worked out the correct solution which works with python newer than 3.5 and all the variables I'm tripping over.

from typing import Any, TYPE_CHECKING

if TYPE_CHECKING:
    __salt__: Any = None
    __states__: Any = None
    __opts__: Any = None
  • Related