python / python/mypy

false-positive `name-defined` regression with dataclasses and shadowing

Đang mở
#12,907 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

bug topic-dataclasses topic-runtime-semantics topic-variable-scope
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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 03901ef657daf6f477e6fe933c42ac270cf5034b ("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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện báo cáo bằng ví dụ test.py được cung cấp, sau đó kiểm tra commit 03901ef657daf6f477e6fe933c42ac270cf5034b và các thay đổi dataclass-transform mà commit này đã đưa vào. Truy vết lý do annotation trên collections ảnh hưởng đến annotation tiếp theo và xác minh rằng ví dụ không còn tạo ra lỗi false-positive name-defined.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.