Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4821)

Issue 554970043: More changes for compatbility with future Python versions

Can't Edit
Can't Publish+Mail
Start Review
Created:
3 weeks, 6 days ago by hahnjo
Modified:
3 weeks ago
Reviewers:
lemzwerg
CC:
lilypond-devel_gnu.org
Visibility:
Public.

Description

More changes for compatibility with future Python versions Python 3 has a few breaking changes that are not automatically handled by running 2to3. However, the required changes also work in older versions of Python, so just apply them right now. Individual changes: 1. Fix empty regex for re.split() Avoid a bunch of problems for newer versions of Python 3 (see below for details) by specifying the non-empty regex \s+ instead of \s*. This is backwards compatible to all versions of Python 2. In Python2, the documentation said "Note that split will never split a string on an empty pattern match." An example: $ python2.7 -c "import re; print re.split('\s*', 'ab cd')" ['ab', 'cd'] This has gradually changed in the life of Python3: On Ubuntu 18.04 with Python 3.6.8 the equivalent command returns (note the warning!) $ python3 -c "import re; print(re.split('\s*', 'ab cd'))" /usr/lib/python3.6/re.py:212: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) ['ab', 'cd'] For Python 3.7, the documentation now describes the following behavior: "Empty matches for the pattern split the string only when not adjacent to a previous empty match." Consequently: $ python3.7 -c "import re; print(re.split('\s*', 'ab cd'))" ['', 'a', 'b', '', 'c', 'd', ''] 2. Use future's division in scripts This is the default in Python 3.0, but we can get it now by adding from __future__ import division which is available since Python 2.2.

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+21 lines, -11 lines) Patch
M python/book_docbook.py View 1 chunk +1 line, -1 line 0 comments Download
M python/book_html.py View 1 chunk +1 line, -1 line 0 comments Download
M python/musicexp.py View 3 chunks +6 lines, -3 lines 0 comments Download
M scripts/abc2ly.py View 3 chunks +5 lines, -3 lines 0 comments Download
M scripts/midi2ly.py View 3 chunks +4 lines, -2 lines 0 comments Download
M scripts/musicxml2ly.py View 2 chunks +4 lines, -1 line 0 comments Download

Messages

Total messages: 1
lemzwerg
3 weeks, 6 days ago (2019-11-10 20:52:48 UTC) #1
LGTM, thanks.

In the patch description: s/divison/division/
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b