Fix Python 3.7 pycodestyle extraneous whitespace regex FutureWarning

less than 1 minute read

From the Python 3.7 beta through today and including pycodestyle 2.4.0 any invocation of pycodestyle results in:

~/miniconda3/lib/python3.7/site-packages/ FutureWarning: Possible nested set at position 1 EXTRANEOUS_WHITESPACE_REGEX = re.compile(r’[[({] | []}),;:]’)


A workaround for this issue is to edit ~/miniconda3/lib/python3.7/site-packages/, replacing

# EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({] | [\]}),;:]')

This eliminates the nuisance warning message.

Why this happens

This warning is a result of Python 3.7 accomodating future Unicode changes:

Support for nested sets and set operations in regular expressions as in Unicode Technical Standard #18 might be added in the future. This would change the syntax. To facilitate this future change a FutureWarning will be raised in ambiguous cases for the time being. That include sets starting with a literal ‘[’ or containing literal character sequences ‘–’, ‘&&’, ‘~~’, and ‘   ’. To avoid a warning, escape them with a backslash. (Contributed by Serhiy Storchaka in bpo-30349.)



Leave a Comment