Skip to content

used-before-assignment false negative with TYPE_CHECKING #8198

@DanielNoord

Description

@DanielNoord

Bug description

Within functions used-before-assignment doesn't get raised for some edge cases.

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from datetime import datetime

# pylint: disable=missing-function-docstring, missing-module-docstring


def func_two():
    second = datetime.now()
    return second


def func():
    first: datetime
    first = datetime.now()
    second = datetime.now()
    return first, second

Configuration

Default config.

Command used

pylint

Pylint output

************* Module test
test.py:10: [E0601(used-before-assignment), func_two] Using variable 'datetime' before assignment


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

Expected behavior

************* Module test
test.py:10: [E0601(used-before-assignment), func_two] Using variable 'datetime' before assignment
test.py:16: [E0601(used-before-assignment), func_two] Using variable 'datetime' before assignment


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

Pylint version

2.16.1

OS / Environment

/

Additional dependencies

No response

Metadata

Metadata

Assignees

Labels

C: used-before-assignmentIssues related to 'used-before-assignment' checkFalse Negative 🦋No message is emitted but something is wrong with the code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions