Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

Fix Python 3.7 pycodestyle extraneous whitespace regex FutureWarning

$
0
0

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/pycodestyle.py:113: FutureWarning: Possible nested set at position 1 EXTRANEOUS_WHITESPACE_REGEX = re.compile(r’[[({] | []}),;:]’) Workaround

A workaround for this issue is to edit ~/miniconda3/lib/python3.7/site-packages/pycodestyle.py , 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.)

Viewing all articles
Browse latest Browse all 9596

Trending Articles