Option to include `init=False` globally on a converter, not per class
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start with cattrs.Converter and the cattrs.strategies.include_init_false entry point mentioned in the issue, then inspect how converter configuration affects attrs classes. Verify the chosen global option with structure and unstructure examples containing init=False fields, and add coverage showing the old behavior is enabled for multiple classes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- cattrs version: v23.2.3
- Python version: 3.11.6
- Operating System: Ubuntu
Description
On previous cattrs versions, I used to structure and unstructure a lot of attrs classes that had many init=False fields.
Now, though, with the new versions of cattrs (v23.2.0), this behavior changed, breaking my code.
I'd like to be able to enable the old behavior back globally on a converter, instead of having to enable it for every single class, as I have many classes all over the place that would benefit from re-enabling init=False fields in conversion.
import attrs
import cattrs
@attrs.define
class Foo:
bar: int
baz: str = attrs.field(init=False)
foo = Foo(bar=1)
foo.baz = "hello"
converter = cattrs.Converter()
print(converter.unstructure(foo))
# before: {'bar': 1, 'baz': 'hello'}
# after: {'bar': 1}
I thought about something like this:
import cattrs
from cattrs.strategies import include_init_false
converter = cattrs.Converter()
include_init_false(converter)
# OR
converter = cattrs.Converter(include_init_false=True)
- Ngôn ngữ chính
- Python
- Star
- 1.1k
- Fork
- 165
- Merge trung bình
- 16 giờ 19 phút
- Pull request đã merge (30 ngày)
- 8
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 python-attrs/cattrs
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python-attrs/cattrs#761 · 2 bình luận ·
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 64/100
python-attrs/cattrs#513 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Literal discriminator ignores override(rename=...), so union structuring fails with KeyErrorĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
python-attrs/cattrs#779 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 85/100
python-attrs/cattrs#774 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
python-attrs/cattrs#746 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python-attrs/cattrs
Issue tương tự
-
customer-reported
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Azure/azure-cli#34150 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
community-request
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
NVIDIA-NeMo/Curator#2464 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
weblate-discover crashes with an unhandled FileNotFoundError when the directory does not existĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
WeblateOrg/translation-finder#1099 ·
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 68/100
trezor/trezor-firmware#7997 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày