Skip to content

Type-hinted additional-builtins raise error since 2.12 #6388

@jgraichen

Description

@jgraichen

Bug description

# pylint: disable=missing-docstring

from typing import TYPE_CHECKING, Any, Dict

if TYPE_CHECKING:
    __additional_builtin__: Dict[str, Any]


def run():
    return __additional_builtin__["test"]

This example will warn about __additional_builtin__ being an undefined-variable since 2.12.0 despite __additional_builtin__ being listed in .pylintrc.

Without the type hints, no warning is issued.

I looked at the source code, and tested it locally, and the new warning is added here: https://github.com/PyCQA/pylint/blob/main/pylint/checkers/variables.py#L1683-L1685=

The __additional_builtin__ variables is correctly identified as only previously assigned as a type hint, but the branch does not check for VARIABLES.additional-builtins as, for example, here: https://github.com/PyCQA/pylint/blob/main/pylint/checkers/variables.py#L1438=


I am developing a few plugins, e.g. for saltstack/salt, which are invoked with additional built ins by salt. Pylint is used in CI and the version maintained by renovate-bot. That highlighted the first failures here: jgraichen/salt-tower#25

Configuration

[VARIABLES]
additional-builtins=__additional_builtin__

Command used

pylint test.py

Pylint output

************* Module test
test.py:10:11: E0602: Undefined variable '__additional_builtin__' (undefined-variable)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior


--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

Pylint version

pylint 2.13.5
astroid 2.11.2
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110]

OS / Environment

Debian 11

Additional dependencies

No response

Metadata

Metadata

Labels

Bug 🪲C: undefined-variableIssues related to 'undefined-variable' checkFalse Positive 🦟A message is emitted but nothing is wrong with the code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions