python / python/mypy

No error when attempting to use property object as that property's type

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

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

priority-2-low topic-descriptors topic-named-tuple topic-runtime-semantics
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
54

Mô tả

  • Are you reporting a bug, or opening a feature request? Bug
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
from typing import NamedTuple


class C(NamedTuple):
    a: int = 1


print(C.a * 2)
  • What is the actual behavior/output?

mypy a.py produces no output.

  • What is the behavior/output you expect?

An error at C.a * 2, as it will cause an error at runtime: TypeError: unsupported operand type(s) for *: 'property' and 'int'

  • What are the versions of mypy and Python you are using?

python --version: 3.7.2
mypy --version: 0.660+dev.97d7760dca6d95806a97b02992ae88a082898a0e

Do you see the same issue after installing mypy from Git master? Yes

  • What are the mypy flags you are using? (For example --strict-optional) None

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

Bắt đầu bằng cách chạy mypy a.py với ví dụ được báo cáo và xác nhận rằng nó không tạo ra đầu ra nào, trong khi Python phát sinh TypeError đã nêu. Theo dõi cách mypy xử lý việc truy cập thuộc tính NamedTuple và biểu thức số học; hoàn tất khi mypy báo lỗi tại C.a * 2 trong trường hợp này.

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
compilers
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
45/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.