- **labels**: --> Fixed_2_21_0
- **status**: Started --> Fixed
- **Patch**: push -->
---
** [issues:#5598] More changes for compatbility with future Python versions**
**Status:** Fixed
**Labels:** Fixed_2_21_0
**Created:** Sun Nov 10, 2019 07:41 PM UTC by Jonas Hahnfeld
**Last Updated:** Mon Nov 18, 2019 09:02 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', '']
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 availble since Python 2.2.
http://codereview.appspot.com/554970043
---
Sent from sourceforge.net because [email protected] 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/testlilyissues-auto