Skip to content

Commit dd79d0f

Browse files
bcallerBen Caller
authored and
Ben Caller
committed
Python 3.7 regex bug fixed
Added py37 to tox environment list. It finds an error with my previous PR: The docs show a change in `Pattern.sub`. ``` Changed in version 3.7: Unknown escapes in repl consisting of '\' and an ASCII letter now are errors. ``` ``` >>> import re >>> DOLLAR_FINDER = re.compile(r"(?<!\\)\$") >>> DOLLAR_FINDER.sub(r'\Z', 'hello$') Traceback (most recent call last): File "/usr/local/lib/python3.7/sre_parse.py", line 1021, in parse_template this = chr(ESCAPES[this][1]) KeyError: '\\Z' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.7/re.py", line 309, in _subx template = _compile_repl(template, pattern) File "/usr/local/lib/python3.7/re.py", line 300, in _compile_repl return sre_parse.parse_template(repl, pattern) File "/usr/local/lib/python3.7/sre_parse.py", line 1024, in parse_template raise s.error('bad escape %s' % this, len(this)) re.error: bad escape \Z at position 0 >>> DOLLAR_FINDER.sub(r'\\Z', 'hello$') 'hello\\Z' ```
1 parent bcfb834 commit dd79d0f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

fastjsonschema/draft04.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def generate_pattern(self):
221221
with self.l('if isinstance({variable}, str):'):
222222
pattern = self._definition['pattern']
223223
safe_pattern = pattern.replace('"', '\\"')
224-
end_of_string_fixed_pattern = DOLLAR_FINDER.sub(r'\Z', pattern)
224+
end_of_string_fixed_pattern = DOLLAR_FINDER.sub(r'\\Z', pattern)
225225
self._compile_regexps[pattern] = re.compile(end_of_string_fixed_pattern)
226226
with self.l('if not REGEX_PATTERNS["{}"].search({variable}):', safe_pattern):
227227
self.l('raise JsonSchemaException("{name} must match pattern {}")', safe_pattern)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# and then run "tox" from this directory.
55

66
[tox]
7-
envlist = py{34,35,36}
7+
envlist = py{34,35,36,37}
88

99
[testenv]
1010
whitelist_externals =

0 commit comments

Comments
 (0)