This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Make it easier to backport statistics to 2.7
Type: behavior Stage: resolved
Components: Versions: Python 3.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, georg.brandl, larry, lemburg, pitrou, r.david.murray, steven.daprano, terry.reedy, vstinner
Priority: normal Keywords: patch

Created on 2013-11-25 07:31 by christian.heimes, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
statistics_backports.patch christian.heimes, 2013-11-25 07:31 review
Messages (11)
msg204301 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-11-25 07:31
A while ago I created a backport of statistics to Python 2.6 to 3.3. [1] It worked pretty and required just a few modifications to the code. I'd like to add most modifications to 3.4 to simplify backporting.

The modifications are:

* from __future__ import division
* replace super() with super(MySuperClass, self)
* changes to doc tests because Python 2 has slightly different represenstations (<type 'float'> / <class'float'>, longer float repr)
* "import collections" -> "from collections import Counter" so I can simply add a Counter class for 2.6
* "import math" -> "from math import isfinite" so it's easier to add a isfinite() function for 2.x

The patch does neither remove "raise ... from None" nor does it add a 2.x isfinite or range = xrange. The backport still needs some patches but I can keep the amount of changes rather small.

[1] https://bitbucket.org/tiran/backports.statistics
msg204302 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-11-25 07:43
-1.

First, I don't think stdlib modules should be forced to use old conventions and give up on new features just because of backports (the import changes are fine obviously).

Second, it's putting unreasonable constraints on CPython developers to know which modules should be compatible with which version and which features that requires to ignore (Python 2.6 is not even in maintenance anymore!)  This is the onus of the backporter (and you have done it already, anyway).

Third, it's also a little late for this given that we're now in beta.
msg204307 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-11-25 08:19
Python's stdlib contains other modules that contain code for older versions of Python. The platform module even contains lines like "os.devnull was added in Python 2.4, so emulate it for earlier". asyncio has backward compatibility code, too. The only old syntax I'd like to add is the super() thing in the test module. They are just tests...

The modified imports and doc test adjustments like

-    >>> mean([1, 2, 3, 4, 4])
-    2.8
+    >>> mean([1, 2, 3, 4, 4]) == 2.8
+    True

would greatly help, though.
msg204332 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-25 12:31
This is a tricky one.  I can see the arguments either way, but it just feels wrong to have future imports in stdlib code.

I personally don't see anything wrong with the import and doctest changes, though.  Sure, someone may come along later and unknowingly break something for your backport, but it isn't likely and IMO it's no big deal if it happens, you can just fix it when your tests fail.  I also don't mind the super call change personally, but that is much more likely to get changed by someone later, since I'm sure other people find it uglier than I do :)

Platform kind of operates under its own rules.  I suppose asyncio does as well :)
msg204340 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-25 13:01
If you started at 2.7 you would need less changes.
msg204343 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-25 13:11
"Python's stdlib contains other modules that contain code for older versions of Python. The platform module even contains lines like "os.devnull was added in Python 2.4, so emulate it for earlier"."

I never understood why the platform module should be backport compatible. Marc Andre Lemburg wrote that it is shipped externally. I don't understand the purpose of having a third party platform module since the module is part of the stdlib.
msg204345 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-25 13:15
> I'd like to add most modifications to 3.4 to simplify backporting.

I would prefer to not touch Python 3.4 backport just to simplify backporting. For example, I don't expect "from __future__ import division" in new Python 3.4 modules, but only on old modules.

If the Python 3.4 evolves, you can use tools like meld to compare your backport and the latest version, and merge manually new changes. Or read Mercurial history of the Python 3.4 module to get patches.

For example, I maintain the faulthandler like that. I manually merge changes when I fix an issue in the CPython version. The version on PyPI is different: it uses SIGALRM instead of a thread, use PyInt_xxx() functions on Python 2, etc.

Do we expect many changes in the statistics modules?
msg204350 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-25 13:35
FWIW, I sympathize with Christian's goal here, since I'm gonna have to backport pathlib too :-)

However, I think the following changes do make the docstrings less readable:

-    >>> mean([1, 2, 3, 4, 4])
-    2.8
+    >>> mean([1, 2, 3, 4, 4]) == 2.8
+    True
msg204351 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-11-25 13:44
> However, I think the following changes do make the docstrings less readable:

Doctests are not reliable. IMO it's better to use unittest with testcases. unittest is easier to maintain, work with Python 2 and 3, and usually provide more useful reports on error.

unittest has more features like functions to skip a test on a specific platform.
msg204385 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-11-25 19:42
As Victor says, I'm not keen on those examples in the stdlib that do this, I'd rather get rid of all of them.

And yes, doctests are only useful if they are written in the simplest possible way.  Otherwise unittest style tests should be preferred.
msg204771 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-11-30 03:56
I too prefer to move in the direction of less back-compatibility constraint rather than more.

If I had written the module, I would prefer the altered doctest as being less fragile and representation dependent. For 1 or 2 objects, I prefer the from form anyway. So yes to those from me.

I am curious what Steven thinks, should he care to opine.
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 63962
2016-09-10 21:29:16christian.heimessetstatus: open -> closed
resolution: wont fix
stage: patch review -> resolved
2013-11-30 03:56:57terry.reedysetnosy: + terry.reedy
messages: + msg204771
2013-11-25 19:42:08georg.brandlsetmessages: + msg204385
2013-11-25 13:44:41vstinnersetmessages: + msg204351
2013-11-25 13:35:13pitrousetmessages: + msg204350
2013-11-25 13:15:04vstinnersetmessages: + msg204345
2013-11-25 13:11:19vstinnersetnosy: + vstinner, lemburg
messages: + msg204343
2013-11-25 13:01:32pitrousetnosy: + pitrou, steven.daprano
messages: + msg204340
2013-11-25 12:31:08r.david.murraysetnosy: + r.david.murray
messages: + msg204332
2013-11-25 08:19:51christian.heimessetmessages: + msg204307
2013-11-25 07:43:15georg.brandlsetnosy: + georg.brandl
messages: + msg204302
2013-11-25 07:31:36christian.heimescreate