#3947 Test 'test_style' (flake8) failing with W605 errors
Closed: Fixed 5 years ago Opened 5 years ago by anshukira.

I submitted a PR #3945 but the CI build failed. Upon further investigation, I saw that the Test test_style (flake8) have been failing with numerous W605 errors such as:

pagure/pagure/utils.py:411:8: W605 invalid escape sequence '\.'
pagure/pagure/utils.py:411:10: W605 invalid escape sequence '\d'

The reason is due to regex strings like the following:

ip_middle_octet = "(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
ip_last_octet = "(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"

Regex escape sequences such as \. raises DeprecationWarning in Python 3.6 when not using 'r' prefix. Flake8 now warns about it.

https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals

Changed in version 3.6: Unrecognized escape sequences produce a DeprecationWarning.
In some future version of Python they will be a SyntaxError.

As far as I understand, the solution is to use prefixes such as:

ip_middle_octet = r"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
ip_last_octet = r"(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"

I believe this is backward-compatible and non-breaking. If this is the correct way to go, I will prepare a PR for this as well.


Flake8 released a new version 9 hours ago which is causing the previously ignored errors to default as per https://gitlab.com/pycqa/flake8/issues/468. Maybe the version of flake8 wasn't pinned down?

Metadata Update from @pingou:
- Issue assigned to karsten
- Issue set to the milestone: 5.2
- Issue tagged with: debt, easyfix

5 years ago

Am i able to help on this?

Metadata Update from @karsten:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

5 years ago

Login to comment on this ticket.

Metadata