-
Notifications
You must be signed in to change notification settings - Fork 239
Booleans are accepted for type integer #144
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
Comments
what you show is Python's intended design. can you elaborate your use-case? |
btw, gh's markdown renders code between three backticks (not very accessible on qwertz-layouts). |
The usecase is a customer facing api where I use cerberus for input validation. I want to clearly distinguish between truth values (true/false) and integers (1....1024). Of course you are right about the python design choice, but I would rather not like to expose python internal "way-of-doing-things" to a backend neutral api. So my suggestion is to keep the current way of handling bool/int for backwards compatibility and provide something like a "strict" parameter which enforces that int has to be a number and not a boolean. |
I think boolean is already strict - I guess only integer would require a "stricter" version - something like "integer_strict" or such. The change itself should be quite trivial:
|
would the more generic |
Although "number" is very generic in regards to int/float, but I think it would be a good fit. |
yep, it isn't bound to a builtin-type anyway. and numbers are infinite while 'true' / 'false' are (questionable,) very finite / determined concepts. ;-) |
I apologize for commenting on an already closed issue. @mbalser #144 (comment) depicts precisely my opinion on this, and for me "number" is not suitable. Can you elaborate on the justification to expose Python's implementation details to a high-level tool like is Cerberus? (I sincerely hope |
well, the types are not all high-level i think (e.g. meanwhile a release candidate has taken form; it would be possible to change that and break bw-compatibility. i think it's okay to be more strict as
if that is the case, it must be changed as other interpreters may implement it differently. someone must lookup the specs. |
I'm new to Cerberus and recently stumbled upon this aspect of its design. I am validating some data structure decoded from a JSON string (in the context of a web API), and was surprised to find that a JS boolean, which gets mapped to a Python boolean by the JSON decoding, validates against a Cerberus |
Internally cerberus 0.10 does the following:
Of course I could map True and False to integers using Value Coercion, but this seems awkward and feels it is not the correct thing to do when using a type check for integers and not explicitly for booleans.
The text was updated successfully, but these errors were encountered: