Mô tả lỗiNếu ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)0 có ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)1 dưới dạng pylint giá trị cho thấy dương tính giả cho "đối tượng không thể mô tả". Tuy nhiên, điều này được phát hiện chính xác bởi, ví dụ, MYPY và phần mở rộng Python trong VSCode. Sau này thậm chí còn cung cấp hoàn thành Intellisense cho tên đăng ký. Show # pylint: disable=missing-class-docstring, missing-module-docstring, missing-function-docstring, invalid-name from enum import Enum from typing import TypedDict class TypedDictionary(TypedDict): name: str class Enumerations(Enum): KEY1: TypedDictionary = {"name": "from enum"} def return_enum_value() -> TypedDictionary: return Enumerations.KEY1.value def return_typed_dict() -> TypedDictionary: return {"name": "from function"} if __name__ == "__main__": value1: TypedDictionary = {"name": "flat"} assert value1["name"] == "flat" value2 = return_typed_dict() assert value2["name"] == "from function" value3 = Enumerations.KEY1.value assert value3["name"] == "from enum" value4 = return_enum_value() assert value4["name"] == "from enum" Cấu hìnhKhông phản hồi Lệnh được sử dụngĐầu ra pylint************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object) Hành vi mong đợi************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)2 và ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)3 không nên được hiển thị là không thể mô tả. Phiên bản pylintpylint 2.14.5 astroid 2.11.7 Python 3.10.5 (main, Jun 23 2022, 17:14:57) [Clang 13.1.6 (clang-1316.0.21.2.5)] Hệ điều hành / môi trườngMacOS 12,5 ZSH 5.8.1 (x86_64-apple-darwin21.0) VSCODE 1.70.0 (Universal) với Python Extension V2022.12.0 Phụ thuộc bổ sungKhông phản hồi Jukkal đã thêm một cam kết tham chiếu vấn đề này Ngày 4 tháng 5 năm 2021
A union of enum literals was merged back to the enum type, which broke
type narrowing. Disable merging in this case to work around the
issue.
The fix feels a bit ad hoc. However, I'd rather not spend a lot of
time figuring out a general fix, since this seems like a pretty rare
edge case.
Fixes #10414. Jukkal đã thêm một cam kết tham chiếu vấn đề này Ngày 4 tháng 5 năm 2021
A union of enum literals was merged back to the enum type, which broke
type narrowing. Disable merging in this case to work around the
issue.
The fix feels a bit ad hoc. However, I'd rather not spend a lot of
time figuring out a general fix, since this seems like a pretty rare
edge case.
Fixes #10414. Mặc dù điều này không trả lời câu hỏi như được hỏi, tôi nghĩ bạn cũng có thể xem xét lại lý do tại sao bạn sử dụng ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)1 với một chuỗi thay vì một lớp thích hợp để giữ enum (thay vì ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)5, vì ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)6 thực sự có vẻ như là một enum ), và sau đó có thể sử dụng một số logic tuần tự hóa tùy chỉnh. Ví dụ:
Ngoài ra, bạn có thể có ENUM kế thừa từ ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)5 và đơn giản hóa một vài điều:
Những ý kiến khác:
Cuối cùng, tôi muốn lưu ý rằng việc xác định pylint 2.14.5 astroid 2.11.7 Python 3.10.5 (main, Jun 23 2022, 17:14:57) [Clang 13.1.6 (clang-1316.0.21.2.5)]3 trên enum của tôi đã không làm những gì tôi mong đợi nó sẽ làm bằng cách sử dụng ví dụ ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)1 của bạn ở trên; Đó là bởi vì str (mydict) gọi pylint 2.14.5 astroid 2.11.7 Python 3.10.5 (main, Jun 23 2022, 17:14:57) [Clang 13.1.6 (clang-1316.0.21.2.5)]5 để cung cấp mỗi pylint 2.14.5 astroid 2.11.7 Python 3.10.5 (main, Jun 23 2022, 17:14:57) [Clang 13.1.6 (clang-1316.0.21.2.5)]6:
Ngoài ra, bạn không thể thêm các phương thức tùy chỉnh vào ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)1; Nếu bạn thay đổi pylint 2.14.5 astroid 2.11.7 Python 3.10.5 (main, Jun 23 2022, 17:14:57) [Clang 13.1.6 (clang-1316.0.21.2.5)]8 thành kế thừa từ ************* Module test test.py:30:11: E1136: Value 'value3' is unsubscriptable (unsubscriptable-object) test.py:33:11: E1136: Value 'value4' is unsubscriptable (unsubscriptable-object)1 và chạy lại ví dụ cuối cùng đó, bạn sẽ không thấy rằng A union of enum literals was merged back to the enum type, which broke
type narrowing. Disable merging in this case to work around the
issue.
The fix feels a bit ad hoc. However, I'd rather not spend a lot of
time figuring out a general fix, since this seems like a pretty rare
edge case.
Fixes #10414. 0 và pylint 2.14.5 astroid 2.11.7 Python 3.10.5 (main, Jun 23 2022, 17:14:57) [Clang 13.1.6 (clang-1316.0.21.2.5)]3 đều không được gọi và thật không may, cũng không có lỗi thời gian chạy ( A union of enum literals was merged back to the enum type, which broke
type narrowing. Disable merging in this case to work around the
issue.
The fix feels a bit ad hoc. However, I'd rather not spend a lot of
time figuring out a general fix, since this seems like a pretty rare
edge case.
Fixes #10414. 2 cảnh báo một cách hữu ích A union of enum literals was merged back to the enum type, which broke
type narrowing. Disable merging in this case to work around the
issue.
The fix feels a bit ad hoc. However, I'd rather not spend a lot of
time figuring out a general fix, since this seems like a pretty rare
edge case.
Fixes #10414. 3). Bởi vì logic tuần tự hóa dường như thuộc về A union of enum literals was merged back to the enum type, which broke
type narrowing. Disable merging in this case to work around the
issue.
The fix feels a bit ad hoc. However, I'd rather not spend a lot of
time figuring out a general fix, since this seems like a pretty rare
edge case.
Fixes #10414. 4, tôi đã thay đổi nó thành một lớp có phần tương tự cho phép tôi tùy chỉnh pylint 2.14.5 astroid 2.11.7 Python 3.10.5 (main, Jun 23 2022, 17:14:57) [Clang 13.1.6 (clang-1316.0.21.2.5)]3 của nó: một DataClass. |