Skip to content
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

Use JS regex syntax #609

Merged
merged 6 commits into from
Oct 7, 2019
Merged

Use JS regex syntax #609

merged 6 commits into from
Oct 7, 2019

Conversation

Zac-HD
Copy link
Member

@Zac-HD Zac-HD commented Oct 4, 2019

Note that js_regex.compile has a cache, just like re.compile, so calling it in loops does a lot of dict lookups but very little work.

Closes #607.

@codecov
Copy link

codecov bot commented Oct 4, 2019

Codecov Report

Merging #609 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #609      +/-   ##
==========================================
+ Coverage    96.1%   96.11%   +<.01%     
==========================================
  Files          18       18              
  Lines        2416     2417       +1     
  Branches      306      306              
==========================================
+ Hits         2322     2323       +1     
  Misses         79       79              
  Partials       15       15

@@ -92,10 +93,10 @@ def find_additional_properties(instance, schema):
"""

properties = schema.get("properties", {})
patterns = "|".join(schema.get("patternProperties", {}))
patterns = "|".join(sorted(schema.get("patternProperties", {})))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting ensures that this is always a single entry in the regex cache, which is quite important for performance (of this tiny function, anyway).

@Julian
Copy link
Member

Julian commented Oct 4, 2019

Hooray, thanks!

Can you also enable the tests for this in the test suite? Should basically just be adding a line like this: https://github.com/Julian/jsonschema/blob/master/jsonschema/tests/test_jsonschema_test_suite.py#L71 to each of the drafts.

@Zac-HD
Copy link
Member Author

Zac-HD commented Oct 4, 2019

Done! I've left out Draft3 because it doesn't have the relevant test cases upstream, which I think is json-schema-org/JSON-Schema-Test-Suite#274.

But drafts 4, 6, and 7 should all be validated... and there's a couple of failures. Welp. ...I think I'll need to take a little longer to debug that, and ensure that I got the everything right upstream 😞

Note that js_regex.compile has a cache, just like re.compile, so calling it in loops does a lot of dict lookups but very little work.
@Zac-HD
Copy link
Member Author

Zac-HD commented Oct 7, 2019

@Julian - I think this just need to be run on top of the fixed version of my upstream tests, and we'll be good to go 😄

Julian added 4 commits October 7, 2019 07:59
433ab2f0 Merge pull request python-jsonschema#286 from Zac-HD/not-patterns
dbaa3aac Fix data - escape unicode, not regex pattern

git-subtree-dir: json
git-subtree-split: 433ab2f0fd6b981527e838cd149c91d823bdc367
* commit 'cdee16959760fe0cd599074cb5d7199eb6ef0d54':
  Squashed 'json/' changes from 2d554504..433ab2f0
@Julian
Copy link
Member

Julian commented Oct 7, 2019

Think we're getting there!

I think there's still one that looks like it's failing: https://travis-ci.org/Julian/jsonschema/jobs/594558002#L3834

@Zac-HD
Copy link
Member Author

Zac-HD commented Oct 7, 2019

Aaaah, I see what's happening there: this isn't one of the "does it match" tests I added - it's actually for {type: string, format: regex}. Compiling with js_regex instead of re should do the trick 😄

@Zac-HD
Copy link
Member Author

Zac-HD commented Oct 7, 2019

And done! ✨🎉🚀

@Julian Julian merged commit b3f0aad into python-jsonschema:master Oct 7, 2019
@Julian
Copy link
Member

Julian commented Oct 7, 2019

Awesome, well done man, really appreciated.

@Zac-HD Zac-HD deleted the js-regex branch October 9, 2019 10:45
@Zac-HD
Copy link
Member Author

Zac-HD commented Oct 9, 2019

@Julian - any advice on when this will make it to PyPI? I've been asked to support it in hypothesis-jsonschema, but doing so before jsonschema itself will cause lots of test failures...

If it's going to be a while I can write a shim, but I'd feel pretty silly if I did that and you updated the day after!

@Julian
Copy link
Member

Julian commented Oct 9, 2019 via email

@Zac-HD
Copy link
Member Author

Zac-HD commented Oct 9, 2019

Awesome! I'll aim to do my integration tomorrow then 😁

@Julian
Copy link
Member

Julian commented Oct 9, 2019 via email

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

Successfully merging this pull request may close these issues.

Support for ECMA 262 regex patterns
2 participants