-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with Optional and non existing file - wrong error message #28
Comments
Sorry for late response. |
I came across the same issue with extra values today. Here's a trivial code snippet that illustrates the problem:
As you can see, "foo" is in data (and a str as requested by the schema), but there's an additional key "bar" that is not specified by the schema. However, the error message is wrong in that case. I'd expect something like "SchemaError: superfluous key 'bar'" |
this shall be fixed in the last commit in the master (from yesterday) in 9a24674. Below is the output from the master branch, which I consider to be correct: >>> from schema import *
>>> schema = Schema({'foo': str})
>>> schema.validate({'foo': 'good', 'bar': 123})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "schema.py", line 147, in validate
e)
schema.SchemaError: wrong keys 'bar' in {'foo': 'good', 'bar': 123}
>>> we might still need to go through all the examples, and make sure they are in the tests, but I assume it shall be fine now. |
Great! Thanks. |
Testing the original examples with the current master (e94b714): 1# Validation of arguments
schema = Schema({
'<inputHocrFile>': Use(open, error='<inputHocrFile> is not readable'),
# ignore other keys
Optional(str): object })
schema.validate({'<inputHocrFile>':"non existing file"})
Current output: schema.SchemaError: <inputHocrFile> is not readable So this one is resolved. 2schema=Schema({'<inputHocrFile>': Use(open, error="ERR")})
schema.validate({'<inputHocrFile>':"non existing file","a":""})
Current output:
I'm not sure I'd necessarily expect a complaint about the key "a" here. 3schema=Schema({'<inputHocrFile>': Use(open, error="ERR"),str:object})
schema.validate({'<inputHocrFile>':"non existing file"})
Current output:
For schema=Schema({'<inputHocrFile>': Use(open),str:object})
schema.validate({'<inputHocrFile>':"non existing file"}) I do get
though, which I find quite satisfactory. Your expectation, @c-holtermann, seems to be that you would get an error message for each validation problem when there are several. While that may be desirable in some cases, it could also turn out problematic, for example when the validation is computationally costly. But it seems that there has been quite a bit of discussion on this topic here: #8 |
I want to parse command line arguments.
I have this schema:
validating
leads to error message
I expected
Another Schema:
leads to the expected error message when doing
while
leads to
when the correct error message would be about a wrong key "a"
Another Schema:
leads to error message
when the actual error message(s) should have been about a missing file and
So:
There are some errors in error messaging.
Question:
Is the Syntax
possible ?
because that's what I want: Optionally other keys.
The text was updated successfully, but these errors were encountered: