snakemake / snakemake-lang-vscode-plugin

Language support and snippets for Snakemake workflows (Snakefile, *.smk) for Visual Studio Code and Apache Theia.
MIT License
13 stars 13 forks source link

Make type checker aware of `snakemake` global in script files #32

Open jlumpe opened 11 months ago

jlumpe commented 11 months ago

Don't know how easy this is to do with an extension, but an annoyance of writing workflows in VS Code is the implicitly defined snakemake global variable. The type checker is not aware of this and will generate an "undefined variable" warning for each usage.

I'm using the following workaround for this:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from snakemake.script import Snakemake
    snakemake: Snakemake
    snakemake = None  # type: ignore

But it would be really great if this could be automatically applied somehow.

Hugovdberg commented 4 months ago

See snakemake/snakemake#2917, that will allow an explicit from snakemake.script import snakemake at runtime (so no if TYPE_CHECKING needed). I used a solution similar to yours for a while, but by implementing it in snakemake itself, it allows static analysis independent of the editor etc.