Skip to content

Can't instantiate Validator() - TypeError #87

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

Closed
dosena opened this issue Mar 30, 2013 · 13 comments
Closed

Can't instantiate Validator() - TypeError #87

dosena opened this issue Mar 30, 2013 · 13 comments

Comments

@dosena
Copy link

dosena commented Mar 30, 2013

Trying the example for is_valid() from https://python-jsonschema.readthedocs.org/en/latest/validate.html

schema = {"maxItems" : 2}
jsonschema.Draft3Validator(schema).is_valid([2, 3, 4])
Traceback (most recent call last):
File "", line 1, in
File "/home/dn/.local/lib/python2.6/site-packages/jsonschema.py", line 176, in init
resolver = RefResolver.from_schema(schema)
File "/home/dn/.local/lib/python2.6/site-packages/jsonschema.py", line 997, in from_schema
return cls(schema.get("id", ""), schema, _args, *_kwargs)
File "/home/dn/.local/lib/python2.6/site-packages/jsonschema.py", line 983, in init
self.store = _URIDict(store, **_meta_schemas())
TypeError: init() keywords must be strings

@dosena
Copy link
Author

dosena commented Mar 30, 2013

jsonschema.version
u'1.1.0'

@dosena
Copy link
Author

dosena commented Mar 30, 2013

sys.version
'2.6.4 (r264:75706, Dec 7 2009, 18:43:55) \n[GCC 4.4.1]'

@Julian
Copy link
Member

Julian commented Mar 31, 2013

If I recall correctly, this is a bug in early versions of 2.6 (specifically that they didn't support unicode kwargs in early versions). I test (and have installed) 2.6.7, but if I get my hands on an early version I can try to verify that. I'm not sure exactly what to do about this other than that, it's a "bug" more or less. I'll try to investigate a bit more.

@Julian
Copy link
Member

Julian commented Mar 31, 2013

Well, I guess on second thought this wouldn't be too painful to workaround I don't think.

@gazpachoking
Copy link
Contributor

Yeah, I believe 2.6.5 fixed this issue, had similar reports on our project when I switched to unicode literals.

@Julian
Copy link
Member

Julian commented Apr 3, 2013

@dosena it would be awesome if you attempted a pull request for this since you have the setup to test it already. It should be fairly simple, just adding some 'b' prefixes to the keys in a single dict.

@gazpachoking
Copy link
Contributor

@Julian Do we want the keys in the meta_schemas dict to be bytes though?

@Julian
Copy link
Member

Julian commented Apr 3, 2013

I don't know, do we not (I didn't look at what that entails even)?

I think what we really want is for _meta_schemas to go away, since we don't even need it anymore if I remember correctly.

@gazpachoking
Copy link
Contributor

Well, I don't like the idea of storing any strings as bytes, but I do believe you are correct that _meta_schemas can go away. We can probably just transfer meta_schemas data to the RefResolver store in some other way that **kwargs to solve this problem.

@Julian
Copy link
Member

Julian commented Apr 3, 2013

Technically these are neither strings nor bytes I think, they're arbitrary
URIs, although yeah you're right it looks like, all the ones we are
prepopulating look like they should be strings.

I think we want to remove this by just having the resolver walk all of the
validators, which I think we store elsewhere.
On Apr 3, 2013 6:43 PM, "Chase Sterling" [email protected] wrote:

Well, I don't like the idea of storing any strings as bytes, but I do
believe you are correct that _meta_schemas can go away. We can probably
just transfer meta_schemas data to the RefResolver store in some other
way that **kwargs to solve this problem.


Reply to this email directly or view it on GitHubhttps://github.com//issues/87#issuecomment-15870158
.

@gazpachoking
Copy link
Contributor

Do we need to walk anything? Couldn't we just do something like:

self.store = meta_schemas.copy()
self.store.update(store)

And rip out _meta_schemas

@Julian
Copy link
Member

Julian commented Apr 4, 2013

Sounds good, I wasn't looking at the code but that sounds vaguely familiar.
On Apr 3, 2013 8:16 PM, "Chase Sterling" [email protected] wrote:

Do we need to walk anything? Couldn't we just do something like:

self.store = meta_schemas.copy()self.store.update(store)

And rip out _meta_schemas


Reply to this email directly or view it on GitHubhttps://github.com//issues/87#issuecomment-15873546
.

@gazpachoking
Copy link
Contributor

Well, the copy won't actually work, forgot that meta_schemas maps uris to Validators, not schemas. We can still do something similar though.

@Julian Julian closed this as completed in dd02e6f Apr 4, 2013
Julian added a commit that referenced this issue Jun 5, 2015
3481a79 Merge pull request #91 from gelraen/nonanchoredpattern
818553f Update pattern.json
b63c96f Merge pull request #92 from gelraen/escapedref
2f043b0 Update ref.json
1ebe2b4 Add valid instances for escaped ref tests
b117902 Add a test that checks for implicit anchoring
d319afa Merge pull request #90 from bugventure/develop
a2c9de2 Add jsen to the list of validators
6d4adfe Merge pull request #87 from legoktm/protocol-relative
824cb99 Add test case for protocol-relative uri validation

git-subtree-dir: json
git-subtree-split: 3481a793ab6a1042a5973549f735b18f2355fb4e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants