Giter Club home page Giter Club logo

Comments (10)

Julian avatar Julian commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

Hehehe, 'hysterical raisins' :D

from jsonschema.

Julian avatar Julian commented on May 25, 2024

;) not my invention.

from jsonschema.

gazpachoking avatar gazpachoking commented on May 25, 2024

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.

Julian avatar Julian commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

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.

Julian avatar Julian commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

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.

gazpachoking avatar gazpachoking commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.