Indexing a Type Alias of an Enum yields false error
Chưa có ai nhận issue này.
- 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ả
Minimum [not-]working product:
Ah, good old Enums:
from enum import Enum
class EnumClass(Enum):
one = 1
EnumAlias = EnumClass
EnumAlias['one']
test.py:6: error: Type application targets a non-generic function or class
test.py:6: error: Name 'one' is not defined
I'm fairly certain this is not an intentional design choice. Just to be sure, according to documentation:
A type alias does not create a new type. It’s just a shorthand notation for another type – it’s equivalent to the target type except for generic aliases.
Now, Enums actually can't be generic, so I certainly expect the alias to be equivalent. So I think this code should pass (regardless of its usefulness... who wants to alias an Enum anyways?).
Possible Causes
I'm no expert, but I think this is happening because the semantic analyzer deems any IndexExpr a TypeApplication if it has a TypeAlias as a base. Once it's marked as analyzed, it doesn't reach the stage of the expression checker where the Enum type would be recognized and the indexing processed as valid. Whatever the root of the problem, I think there's only one spot where the expression checker actually looks at is_enum to handle Enum indexing, so the alias isn't making it there one way or another.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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 lần theo cách trình phân tích ngữ nghĩa phân loại IndexExpr thành một TypeApplication khi phần cơ sở của nó là một TypeAlias, sau đó theo dõi đường đi của bộ kiểm tra biểu thức xử lý is_enum. Xác minh rằng ví dụ EnumAlias['one'] không còn tạo ra cả hai lỗi đã được báo cáo, và thêm kiểm thử hồi quy cho 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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100