Skip to content

false-positive name-defined regression with dataclasses and shadowing #12907

Open
@The-Compiler

Description

@The-Compiler

Bug Report

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.

Actual Behavior

mypy v0.950 was happy with it, but mypy v0.960 claims that:

test.py:9: error: Name "collections.defaultdict" is not defined

Introducing commit

Bisected to 03901ef ("Running dataclass transform in a later pass to fix crashes (#12762)", @JukkaL)

Your Environment

  • Mypy version used: v0.960
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.4
  • Operating system and version: Archlinux

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions