comparison contrib/check-code.py @ 36963:a8d540d2628c

contrib: fix a subtle bug in check-code's regex rewriting We rewrite `\s` to `[ \t]` when preparing our regular expressions, but we previously weren't working to avoid having nested sets. Previously, Python let this slide without incident, but in Python 3.7 wants to make sure you meant an actual [ in a set, and so this warns. This appears to be fortunate for us, because `[\s(]` was getting rewritten to be `[[ \t](]` which doesn't actually match what we expected. See preceding changes that were revealed to be necessary after implementing this fix. Differential Revision: https://phab.mercurial-scm.org/D2866
author Augie Fackler <augie@google.com>
date Wed, 14 Mar 2018 14:05:45 -0400
parents 35d814fe2f30
children 79af9ae46a78
comparison
equal deleted inserted replaced
36962:b710fdebd0db 36963:a8d540d2628c
540 failandwarn = c[-1] 540 failandwarn = c[-1]
541 for pats in failandwarn: 541 for pats in failandwarn:
542 for i, pseq in enumerate(pats): 542 for i, pseq in enumerate(pats):
543 # fix-up regexes for multi-line searches 543 # fix-up regexes for multi-line searches
544 p = pseq[0] 544 p = pseq[0]
545 # \s doesn't match \n 545 # \s doesn't match \n (done in two steps)
546 p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p) 546 # first, we replace \s that appears in a set already
547 p = re.sub(r'\[\\s', r'[ \\t', p)
548 # now we replace other \s instances.
549 p = re.sub(r'(?<!(\\|\[))\\s', r'[ \\t]', p)
547 # [^...] doesn't match newline 550 # [^...] doesn't match newline
548 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p) 551 p = re.sub(r'(?<!\\)\[\^', r'[^\\n', p)
549 552
550 pats[i] = (re.compile(p, re.MULTILINE),) + pseq[1:] 553 pats[i] = (re.compile(p, re.MULTILINE),) + pseq[1:]
551 filters = c[3] 554 filters = c[3]