|
From: | Auto mailings of changes to Lily Issues via Testlilyissues-auto |
Subject: | [Lilypond-auto] [LilyIssues-auto] [testlilyissues:issues] #5598 More changes for compatbility with future Python versions |
Date: | Mon, 18 Nov 2019 21:02:57 -0000 |
Pushed as
commit 850bd4040dc39bfd6e51944e90d7a900965cba66 Author: Jonas Hahnfeld <hahnjo@hahnjo.de> Date: Sun Nov 10 19:50:36 2019 +0100 Issue 5598/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. commit 967a71dc206c3705346aae07a4a229d8a7319203 Author: Jonas Hahnfeld <hahnjo@hahnjo.de> Date: Sun Nov 10 12:02:54 2019 +0100 Issue 5598/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', '']
[issues:#5598] More changes for compatbility with future Python versions
Status: Started
Created: Sun Nov 10, 2019 07:41 PM UTC by Jonas Hahnfeld
Last Updated: Mon Nov 18, 2019 07:57 PM UTC
Owner: Jonas Hahnfeld
More changes for compatbility 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', '']
This is the default in Python 3.0, but we can get it now by adding
from future import division
which is availble since Python 2.2.
http://codereview.appspot.com/554970043
Sent from sourceforge.net because address@hidden is subscribed to https://sourceforge.net/p/testlilyissues/issues/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/testlilyissues/admin/issues/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.
_______________________________________________ Testlilyissues-auto mailing list address@hidden https://lists.sourceforge.net/lists/listinfo/testlilyissues-auto
[Prev in Thread] | Current Thread | [Next in Thread] |