|
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: | Sat, 16 Nov 2019 19:19:53 -0000 |
Diff:
--- old +++ new @@ -29,7 +29,7 @@ $ python3.7 -c "import re; print(re.split('\s*', 'ab cd'))" ['', 'a', 'b', '', 'c', 'd', ''] -2. Use future's divison in scripts +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
[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: Sat Nov 16, 2019 07:04 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] |