fozen_box with lists cannot converted to YAML
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu với Box.to_yaml trong box/box.py và quá trình chuyển đổi đệ quy trong box/converters.py, sau đó tái hiện ví dụ frozen_box=True từ issue. Kiểm tra rằng to_dict loại bỏ các đối tượng Box lồng nhau bên trong các giá trị tuple, và xác nhận rằng cấu trúc thu được có thể được tuần tự hóa thành YAML mà không gặp lỗi representer.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug
Simple example
from box import Box
test_box = Box({'a': [{'b': 123}, {'b': 222}]}, frozen_box=True)
test_box.to_yaml()
This yields the following error:
ruamel.yaml.representer.RepresenterError: cannot represent an object: {'b': 123}
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "box/box.py", line 1013, in box.box.Box.to_yaml
File "box/converters.py", line 207, in box.converters._to_yaml
File "box/converters.py", line 208, in box.converters._to_yaml
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/main.py", line 594, in dump
return self.dump_all([data], stream, transform=transform)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/main.py", line 604, in dump_all
self._context_manager.dump(data)
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/main.py", line 953, in dump
self._yaml.representer.represent(data)
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 83, in represent
node = self.represent_data(data)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 105, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 318, in represent_dict
return self.represent_mapping('tag:yaml.org,2002:map', data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 841, in represent_mapping
node_value = self.represent_data(item_value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 105, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 309, in represent_list
return self.represent_sequence('tag:yaml.org,2002:seq', data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 750, in represent_sequence
node_item = self.represent_data(item)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 115, in represent_data
node = self.yaml_representers[None](self, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/daniel/.local/share/virtualenvs/bedrock-JuU-uWSt/lib/python3.11/site-packages/ruamel/yaml/representer.py", line 347, in represent_undefined
raise RepresenterError(f'cannot represent an object: {data!s}')
ruamel.yaml.representer.RepresenterError: cannot represent an object: {'b': 123}
Investigation
The problem is that - when using frozen_box=True - that lists get converted to tuples. But then test_box.to_dict() does not remove the Boxes from tuples so we have this:
test_box.to_dict()
# {'a': (Box({'b': 123}), Box({'b': 222}))}
which should actually be this:
test_box.to_dict()
# {'a': ({'b': 123}, {'b': 222})}
- 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ự
-
bug Size: XS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
oposs/repo-infra#93 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
Graphify-Labs/graphify#4546 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
521xueweihan/HelloGitHub#4025 ·