Default Box fails to handle singleton instances of itself
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Bắt đầu trong box/box.py tại getitem, getattr và get_default, những vị trí được hiển thị trong traceback. Tái hiện ví dụ singleton TestBox và theo dõi quá trình xây dựng default-box; hoàn thành khi một thuộc tính bị thiếu như env hoạt động đúng mà không xuất hiện KeyError đệ quy như trên.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
It appears that trying to use Default Box in a singleton pattern breaks it. See below for code and traceback
from box import Box
_test_box = None
class TestBox(Box):
def __new__(cls, *args, **kwargs):
global _test_box
if _test_box is None:
_test_box = super().__new__(cls, *args, **kwargs)
return _test_box
def __init__(self, *args, **kwargs):
super().__init__(default_box=True, *args, **kwargs)
self.__test_method()
def __test_method(self):
_this_should_not_fail = self.env
TestBox()
Traceback is as follows
Traceback (most recent call last):
File "/home/miversen/git-local/transcoder/venv/lib/python3.8/site-packages/box/box.py", line 488, in __getitem__
return super().__getitem__(item)
KeyError: 'env'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/miversen/git-local/transcoder/venv/lib/python3.8/site-packages/box/box.py", line 514, in __getattr__
value = self.__getitem__(item, _ignore_default=True)
File "/home/miversen/git-local/transcoder/venv/lib/python3.8/site-packages/box/box.py", line 509, in __getitem__
raise BoxKeyError(str(err)) from _exception_cause(err)
box.exceptions.BoxKeyError: "'env'"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/miversen/git-local/transcoder/venv/lib/python3.8/site-packages/box/box.py", line 516, in __getattr__
value = object.__getattribute__(self, item)
AttributeError: 'TestBox' object has no attribute 'env'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 19, in <module>
c1 = TestBox()
File "test.py", line 14, in __init__
self.__test_method()
File "test.py", line 17, in __test_method
_this_should_not_fail = self.env
File "/home/miversen/git-local/transcoder/venv/lib/python3.8/site-packages/box/box.py", line 529, in __getattr__
return self.__get_default(item, attr=True)
File "/home/miversen/git-local/transcoder/venv/lib/python3.8/site-packages/box/box.py", line 426, in __get_default
value = self._box_config["box_class"](**self.__box_config())
File "test.py", line 13, in __init__
super().__init__(default_box=True, *args, **kwargs)
KeyError: 'default_box'
Environment Details
- Python3: Python 3.8.10
- OS: Ubuntu 20.04.3 LTS
- Kernel: 5.11.0-27-generic
- Ngôn ngữ chính
- Python
- Star
- 2.8k
- Fork
- 145
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc 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.
Issue khác của cdgriffith/Box
-
subclass of `Box` does not unpickle correctlyCó thể đã có người làm @koriyoshi2041 đã nhận 142 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
cdgriffith/Box#308 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
cdgriffith/Box#307 · 1 bình luận ·
-
Dotted keys read from YAML are lost with box_dots / default_boxCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
cdgriffith/Box#305 ·
-
[Bug] Camel killer box and box dots gives unexpected behaviourCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
cdgriffith/Box#300 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
cdgriffith/Box#298 ·
Tất cả issue của cdgriffith/Box
Issue tương tự
-
tunneld on Windows: Wi-Fi devices are not discovered because uvicorn runs on a ProactorEventLoopĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
doronz88/pymobiledevice3#2051 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Remove DatacircleĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
collabnix/awesome-mcp-lists#230 ·
Maintainer thường phản hồi trong vòng 9 ngày
-
Groc schedules with out of range values pass config validation and fail later when the scheduler is builtCó thể đã có người làm @auraseb đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
autowarefoundation/autoware_carla_scenario#342 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ianktoo/project-monitor#14 ·