Skip to main content

variable_declaration_checker

We have migrated to Flake8 as Pylint's performance becomes a bottleneck on larger projects. Since our workflow focuses on file-by-file linting rather than cross-module dependency checks, Flake8 is a better fit. If you still prefer Pylint, use variable-declaration-checker==0.0.7.

Installation and Basic Usage

pip install variable-declaration-checker
flake8 --select WVarDec

Special Cases

We want this plugin to work with Visual Studio Code. Therefore, all behaviors that conflict with Pylance need to be eliminated. For example, if you find that not adding type annotations causes warnings from this plugin, while adding type annotations causes errors in Pylance, please report it to us.

Note that ast does not provide complete type information. This makes it impossible to implement some functions. We may need to expand or narrow the scope of the inspection. The specially handled cases are described below.

self and cls

The first argument of a method (self, or cls for class method) is considered unnecessary to be declared:

# This won't affect the functions that are not defined in a class.
def f1(self):    # WVarDec01 Declare the variable 'self' with type annotation before use.
    pass

class MyClass:
    def f2(self):    # No warning.
        pass
    
    # It check the argument's name and position at the same time:
    # Only the first argument that named "self" or "cls" will considered unnecessary to be declared.
    # This design is to deal with decorators like @staticmethod.

    # This won't be a problem if you use it with Pylance,
    # as Pylance will require you to rename the argument to "self" or "cls" (with a warning).
    # So as you fix the problems in Pylance, the plugin will work as expected.

    def f3(x):    # WVarDec01 Declare the variable 'x' with type annotation before use. Pylance: Instance methods should take a "self" parameter
        pass

    @staticmethod
    def f4(self):    # No warning. However Pylance: Static methods should not take a "self" or "cls"
        pass

Underscores

Underscores (or discards, _) will simply be ignored.

x = ""    # WVarDec01 Declare the variable 'x' with type annotation before use.
x: str = ""    # WVarDec02 The variable 'x' is declared twice. Rename it or 'del' it if needed.

_ = ""    # No warning
_: str = ""    # Still no warning

Enums

If you use type annotation for enum members, Pylance will say "Type annotations are not allowed for enum members". So the checker will skip for enum numbers. However, due to the limitations of ast, we can only roughly determine whether a type is an Enum by its base class name:

from enum import Enum, IntFlag
import enum

class NotE:
    X = 1    # WVarDec01 Declare the variable 'X' with type annotation before use.

class NotE2:
    X: int = 1    # No warnings.

class E1(Enum):
    X: int = 1    # No warnings. However Pylance: Type annotations are not allowed for enum members

class E2(Enum):
    X = 1    # No warnings.

# Supports "Enum", "IntEnum", "StrEnum", "Flag", "IntFlag" and "ReprEnum"
class E3(IntFlag):
    X = 1    # No warnings.

# Supports "enum.Enum", "enum.IntEnum", "enum.StrEnum", "enum.Flag", "enum.IntFlag" and "enum.ReprEnum"
class E4(enum.Flag):
    X = 1    # No warnings.

# FAIL CASES: It can't know the actual class and can only detect by the class name.

# It is not an Enum but
class ReprEnum: pass
class E5(ReprEnum):
    X = 1    # No warnings.

# It is an Enum but
class E6(E1):
    Y = 1    # WVarDec01 Declare the variable 'Y' with type annotation before use.

Metadata

Release files for variable-declaration-checker 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for variable-declaration-checker 0.1.2
File Size Uploaded Provenance
variable_declaration_checker-0.1.2.tar.gz 4.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for variable-declaration-checker 0.1.2
File Interpreter ABI Platform
variable_declaration_checker-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / variable_declaration_checker-0.1.2.tar.gz

Download URL variable_declaration_checker-0.1.2.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2b3505b68e80290016e2c4b8189146a39c93fbbc5951ea289b02981d1cd638e0
BLAKE2b-256 checksum
How to use checksums
46421e94eded56f23625bdf6c1c8c5fbcadfd67c8062ecd994a73726fc1bb9de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / variable_declaration_checker-0.1.2-py3-none-any.whl

Download URL variable_declaration_checker-0.1.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c5b974ca1d76df78bda9560a6c74d92dfb2e7b087a64d8f341b6c3267cc51dae
BLAKE2b-256 checksum
How to use checksums
cd5f879c5baa4e99a23293d3bf44bbe1689f76def06341decf249e8eaedfd3e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for variable-declaration-checker 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page