python / python/mypy

Ior assignment operator is flagged while equivalent __ior__() method call is not

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

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

bug
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

A |= operation statement causes "Result type of | incompatible in assignment" while the equivalent method call is accepted without complaint. I haven't figured out to annotate the statement to prevent that complaint, and expect that the complaint is an error.

To Reproduce

I am composing an OrderedSet based on one of Ramond Hettinger's recipes (the weakref one), adding needed functionality and type annotations. As in the recipe, my OrderedSet class is based on collections.MutableSet. Adding an update method, this definition results in Result type of | incompatible in assignment on the "|=" statement:

def update(self, *others):
        # type: (*AbstractSet) -> None
        for o in others:
            self |= o   # Mypy Error: Result type of | incompatible in assignment

However, code for the method that is identical except for using the corresponding method call instead of the |= operator does not cause any complaints:

def update(self, *others):
        # type: (*AbstractSet) -> None
        for o in others:
            self.__ior__(o)   # No error.

I would prefer to use the |= statement, but have been unable to annotate the unaccepted statement in a way that prevents the complaint (short of using ignore). (There are other methods that suffer from similar obstacles, including the original __init__() included in Raymond's recipe. The example I'm using involves fewer incidental details.)

Expected Behavior

I believe the |= statement should be accepted without complaint.

Actual Behavior

Result type of | incompatible in assignment error on the "|=" statement.

Your Environment

  • Mypy version used: mypy 0.902
  • Python version used: Python 3.7.5
  • Operating system and version: Ubuntu Linux 18.04

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 trên các đoạn mã cập nhật OrderedSet được cung cấp và so sánh câu lệnh |= với lệnh gọi __ior__() tương đương. Theo dõi cách hai dạng này được kiểm tra; hoàn thành khi dạng |= được chấp nhận nhất quán với lệnh gọi phương thức mà không cần ignore.

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
Đặc tả 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.