Comments (10)
Ugh, that first one is going to be a real pain. I'm almost inclined to consider not fixing it. Python's True and False are, for hysterical raisins or not, mostly just 0 and 1 with nice reprs. I know we special case them already for type checking, and that obviously you get those when loading, but I'm curious what is done in languages without booleans like C where the situation is similar.
from jsonschema.
Hehehe, 'hysterical raisins' :D
from jsonschema.
;) not my invention.
from jsonschema.
We could break container down into types and then deal with it:
type_groups = {}
for t, i in itertools.groupby(container, type):
type_groups.setdefault(t, []).extend(i)
EDIT: Not even sure why I used groupby there, artifact of trying to solve the whole problem at once which didn't work due to not being able to sort a list with different types.
from jsonschema.
I think even if we fix this we should probably leave it for now and come
back to it later after we get some more important stuff done.
We have to be careful, bool really is the only special case, which is why
this is pretty sucky. If someone comes up with their own type and hooks it
into json.loads that's up to them, and they should be the ones deciding
which two objects are equal.
On Sunday, October 28, 2012, Chase Sterling wrote:
We could break container down into types and then deal with it:
type_groups = {} for t, i in itertools.groupby(container, type): type_groups.setdefault(t, []).extend(i)
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/43#issuecomment-9855054.
from jsonschema.
I also noticed that the 3 tests in uniqueItems that cause this problem are actually just tests from the enum suite: https://github.com/Julian/jsonschema/blob/master/tests/draft3/uniqueItems.json#L54
EDIT: That did make it easy to ignore them all at once though ;)
from jsonschema.
We could cast bools to a custom class maybe. Then any standard unique tests would work.
class Bool(object):
def __init__(self, bool):
self.bool = bool
def __eq__(self, other):
return other.__class__ == Bool and self.bool == other.bool
container = map(lambda x: Bool(x) if isinstance(x, bool) else x, container)
from jsonschema.
That would be closer to what we'd have to do, yeah. I'm still thinking about whether we should though, and leaning towards shouldn't. In fact I'm even considering we should revert the special casing in is_type
and have {"type" : "integer"}
validate true
. But hey, it's still early in the morning. Let me know what you think. I think we'd confirm on the ML because I still am curious what languages without booleans do.
What I definitely do want to do though is make this a failing test rather than an error. So I think we should simplify the test in enum
to not cause this error, and add another test (for now in optional
) that is specifically testing for this behavior.
from jsonschema.
I think I'm more inclined to fix it. The one case I can see happening, is somebody is allowing multiple forms of true/false in their schema with {"enum": [true, false, 1, 0]}
and then all of a sudden their schema isn't usable with jsonschema, since it won't pass our metavalidation.
from jsonschema.
Possibly cleaner solution, less object creation at least:
true = object()
false = object()
def transform_booleans(o):
if isinstance(o, bool):
return true if o else false
return o
container = map(transform_booleans, container)
from jsonschema.
Related Issues (20)
- Draft07Valiadator doesn't validate dates HOT 1
- Inconsistent behaviour of validator_for depending on http vs https HOT 2
- Validation starting from sub-definition
- Getting schema contents after refs are resolved HOT 1
- `format: uri` doesn't work properly HOT 4
- Issue with oneOf validation HOT 6
- Unable to resolve a realtive `$ref` from a schema with `$id` pointed to a subschema in `$defs` with `$id` HOT 2
- Self referenced schema encapsulation breaks reference resolution HOT 1
- jsonschema.TypeChecker with additional types fails to work after several reference resolutions by the referencing.Registry HOT 2
- validate fails to identify incorrect uuid strings HOT 3
- 'Tuple' arrays not handled correctly HOT 3
- validate() throwing exception for a valid schema HOT 1
- Draft7Validator(TyperError: create.<locals>.Validator.__init__() got an unexpected keyword argument 'registry' HOT 2
- Which is the last version not requiring Rust via its dependencies?
- Migrating From RefResolver, unable to resolve $ref
- Feature request: Add support for a second message attribute on errors which is guaranteed not to include the failing instance HOT 5
- Python NaN validates against all numeric limits, and shouldn't HOT 2
- validating nan in an enum is no longer supported HOT 1
- Need a custom ref resolver
- Support custom Registry for meta schema in check_schema HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonschema.