alecthomas / alecthomas/voluptuous

Inconsistent error due to ordering of Any() arguments

Đang mở
#413 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
1.9k
Fork
237
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Any chance for more comprehensive error returns for Any() failures?

I wanted to make a Schema where a string or list of strings (with a defined list length) was possible.

I wrote it as such:
`b = Schema(Any(str, All([str], Length(min=2))))`
And tested it with the following lines:
1) `b(3)`
2) `b('3')`
3) `b(['3'])`
4) `b(['3', '4'])`

These lines fail as expected - but the returned error message is either:

1. Not correct (Line 3) - `voluptuous.error.MultipleInvalid: expected str`
-- This being the error for not fulfilling the 1st arg of the Any, yet as a list the 2nd arg failing would be more pertinent.

2. Not comprehensive (Line 1) - `voluptuous.error.MultipleInvalid: expected str`
-- By failing all of the Any conditions, surely something more general / comprehensive should be thrown?

By swapping the arg order, the correct error is thrown on line 3 - although forcefully & and not by way of IDing the closest culprit in failure. Line 1 (expectedly) is still specific.

`b = Schema(Any(All([str], Length(min=2)), str))`
1) `voluptuous.error.MultipleInvalid: expected a list`
3) `voluptuous.error.MultipleInvalid: length of value must be at least 2`

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.