Skip to content

False positive used-before-assignment with dataclasses and shadowing #6748

@The-Compiler

Description

@The-Compiler

Bug description

This file:

from dataclasses import dataclass
import collections


@dataclass
class Shadow:

    collections: collections.deque
    other: collections.defaultdict


print(Shadow(collections.deque(), collections.defaultdict()))

is perhaps a bit unorthodox, but runs fine, because the collections: ... doesn't actually shadow the module when defining other.

Configuration

No response

Command used

pylint -E test.py

Pylint output

************* Module test
.../test.py:9:11: E0601: Using variable 'collections' before assignment (used-before-assignment)

Expected behavior

No error.

Pylint version

pylint 2.13.9
astroid 2.11.5
Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0]

OS / Environment

Archlinux

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions