Create validators not tied to attributes
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
The issue names no files or tests; start by reviewing the existing attribute-bound validator behavior shown through @x.validator. Compare it with the proposed class-level @validator and determine how cross-attribute checks should run. Done means a generic validator can enforce the relationship between x and y without being attached to only one attribute, with the behavior covered by tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Currently if I need to add a validator to check a condition that affects two attributes, I have to make it a validator of one of them. For example:
@attr.s
class C(object):
x = attr.ib()
y = attr.ib()
@x.validator
def x_smaller_than_y(self, _ , value):
if value >= self.y:
raise ValueError("'x' has to be smaller than 'y'!")
This feels a little unintuitive because this validator is not really a validator on just 'x'. It should be a validator on 'x' and 'y'. It made me wonder if the order of writing x and y in the class matters, in case the validator is run right after an attribute is set.
I wonder what folks think about a generic validator of this form:
@attr.s
class C(object):
x = attr.ib()
y = attr.ib()
@validator
def x_smaller_than_y(self):
if self.x >= self.y:
raise ValueError("'x' has to be smaller than 'y'!")
- Ngôn ngữ chính
- Python
- Star
- 5.8k
- Fork
- 480
- Merge trung bình
- 2 giờ 15 phút
- Pull request đã merge (30 ngày)
- 2
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/attrs
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
python-attrs/attrs#1620 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
python-attrs/attrs#1596 · 2 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
python-attrs/attrs#1549 · 3 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
python-attrs/attrs#1543 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
python-attrs/attrs#1532 ·
Tất cả issue của python-attrs/attrs
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
stephrobert/dsoxlab#238 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
sublimehq/package_control#1780 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
nwg-piotr/nwg-displays#145 ·