attrs 23.1.0 breaks string annotated generics
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start in converters.py around lines 976-977 and compare the attrs 22.2.0 and 23.1.0 behavior for generic classes with string annotations. Run the supplied A[int] reproduction; done means structuring {'a': 1} succeeds while {'a': 'one'} still fails as expected.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- cattrs version: 23.1.2
- Python version: 3.10.7
- Operating System: Ubuntu
Description
When working with generic attrs types with cattrs, I updated my version of attrs and it caused failures. Having looked at the changelog in attrs:
https://www.attrs.org/en/stable/changelog.html#id1
This seems likely it was caused by:
attrs.has() and attrs.fields() now handle generic classes correctly. #1079
Changing the behaviour of: (converters.py 976-977)
attribs = fields(get_origin(cl) or cl if is_generic(cl) else cl)
if attrs_has(cl) and any(isinstance(a.type, str) for a in attribs):
in which case it probably can't be described as an attrs bug. (But I don't have high confidence in that).
(I confirmed that
resolve_types(cl)
failed on both versions of attrs, so the difference is somewhere in the if statement)
What I Did
from __future__ import annotations
from typing import TypeVar, Generic
import attrs
import cattrs
T = TypeVar('T')
@attrs.frozen
class A(Generic[T]):
a: T
converter = cattrs.Converter()
converter.gen_structure_attrs_fromdict(A[int]) # This fails with attrs 23.1.0
#And hence the lower calls won't work
cattrs.structure({'a': 1}, A[int]) # Succeeds with attrs 22.2.0
cattrs.structure({'a': 'one'}, A[int]) # Fails as expected with attrs 22.2.0
- Ngôn ngữ chính
- Python
- Star
- 1.1k
- Fork
- 171
- Merge trung bình
- 2 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 7
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
-
decimal.Decimal not handled in preconf converters (json, pyyaml)Có thể đã có người làm @Binilkks đã nhận 111 ngày trước. Đang mở
Độ 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
-
Getting the next structure hookĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
python-attrs/cattrs#794 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
python-attrs/cattrs#793 ·
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
Tất cả issue của python-attrs/cattrs
Issue tương tự
-
Path subtraction removes repeated suffix characters instead of one suffixCó thể đã có người làm @Gwerdonatus đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
joke2k/django-environ#671 ·
-
good first issue help wanted windows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
-
test_pgbouncer deploys the server under test from Charmhub instead of the local build (track/1.31)Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
canonical/temporal-k8s-operator#195 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
`burr` fails to start when the Python path has a space in itCó thể đã có người làm @enekoreto đã nhận hôm nay. Đang mởstatus/needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 5 ngày
-
device support request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
zigpy/zha-device-handlers#5461 ·
Maintainer thường phản hồi trong vòng 4 ngày