[issue5191] Partial function application 'from the right'
New submission from Ben North : The functools module includes a 'partial' class, which allows partial function application either by positional arguments or keyword arguments. However, it cannot be used to create, for example, a function splitting a string on commas, or a function to extracts logs to base 10. I posted http://mail.python.org/pipermail/python-dev/2009-January/085638.html which suggested a 'partial_right' feature, such that the following would work: >>> import functools, math >>> split_comma = functools.partial_right(str.split, ',') >>> split_comma('a,b,c') ['a', 'b', 'c'] >>> log_10 = functools.partial_right(math.log, 10.0) >>> log_10(100.0) 2.0 There was some useful discussion, but generally the feeling was that the extra complexity outweighed the potential benefits. Also, chained partial applications were troublesome. The overlap in functionality between 'partial_right' and an existing patch (#1706256) to allow skipping of positional arguments was raised. I think the present issue should probably be closed/rejected, but it was suggested on the mailing list that having the issue and patch on the record might be useful. Patches are against 2.6.1 source. -- messages: 81457 nosy: bennorth severity: normal status: open title: Partial function application 'from the right' type: feature request ___ Python tracker <http://bugs.python.org/issue5191> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5191] Partial function application 'from the right'
Changes by Ben North : -- keywords: +patch Added file: http://bugs.python.org/file12991/_functoolsmodule.patch ___ Python tracker <http://bugs.python.org/issue5191> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5191] Partial function application 'from the right'
Changes by Ben North : Added file: http://bugs.python.org/file12992/test_functools.patch ___ Python tracker <http://bugs.python.org/issue5191> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Change by Ben North : -- pull_requests: +5203 stage: needs patch -> patch review ___ Python tracker <https://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Ben North added the comment: Terry in msg310785: > As I expected from the fact that Ben once did a separate 2.7 > version, the auto backport for 2.7 failed. Ben, since you know what > code changes are needed, can you prepare a backport (cherry pick) > PR? Yes, that's right, there were some differences between the approaches in Py2 and Py3. I've created PR5357 for the 2.7 backport. -- ___ Python tracker <https://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Ben North added the comment: PR4823 created as per msg308086. -- ___ Python tracker <https://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue32137] Stack overflow in repr of deeply nested dicts
Change by Ben North : -- pull_requests: +4716 ___ Python tracker <https://bugs.python.org/issue32137> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
New submission from Ben North: #18019 noted the following crash in earlier 2.7: >>> d={} >>> d[42]=d.viewvalues() >>> d This issue has been fixed; the behaviour now is that a RuntimeError is produced for a recursive dictionary view: >>> d={} >>> d[42]=d.viewvalues() >>> d # (output line-broken:) {42: Traceback (most recent call last): File "", line 1, in RuntimeError: maximum recursion depth exceeded while getting the repr of a list Before finding this, though, I'd investigated and made a patch which produces a similar "..." output to a recursive dictionary. Reworking against current 2.7, the behaviour would be: >>> x={} >>> x[42]=x >>> x # existing behaviour for dictionaries: {42: {...}} >>> d={} >>> d[42]=d.viewvalues() >>> d # new behaviour: {42: dict_values([...])} >>> d[43]=d.viewitems() >>> d # (output line-broken:) {42: dict_values([..., dict_items([(42, ...), (43, ...)])]), 43: dict_items([(42, dict_values([..., ...])), (43, ...)])} Attached is the patch, against current 2.7 branch. If there is interest in applying this, I will create a proper patch (changelog entry, fix to Lib/test/test_dictviews.py, etc.). On python-dev, Gregory Smith noted: Given that the RuntimeError fix has been released, your proposed ... behavior is arguably a new feature so I'd only expect this to make sense for consideration in 3.4, not 2.7. (if accepted at all) [http://mail.python.org/pipermail/python-dev/2013-July/127489.html] so I have marked for consideration for versions 2.7 and 3.4. -- components: Interpreter Core files: non-error-recursive-dictview.patch keywords: patch messages: 193570 nosy: bennorth priority: normal severity: normal status: open title: Avoid error from repr() of recursive dictview type: behavior versions: Python 2.7, Python 3.4 Added file: http://bugs.python.org/file31019/non-error-recursive-dictview.patch ___ Python tracker <http://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Ben North added the comment: New patch including tests attached, against 3.3. Terry Reedy's example above now gives >>> d = {} >>> d[1] = d.keys() >>> d[2] = d.values() >>> d {1: dict_keys([1, 2]), 2: dict_values([dict_keys([1, 2]), ...])} which I think is preferable. Summary of patch: dictobject.c: dictview_repr() now uses a Py_ReprEnter() / Py_ReprLeave() pair to check for recursion, and produces "..." if so. I think I've got the behaviour correct in the case that PySequence_List() fails, but couldn't find a way to trigger this in testing. test_dictviews.py: test_recursive_repr() checks for the correct string (containing "...") rather than a RuntimeError. test_deeply_nested_repr() is a new function, aiming to replace the original test_recursive_repr(). It checks that a RuntimeError is raised in the case of a non-recursive but deeply nested structure. Under --with-pydebug, ./python -m test.regrtest -R20:30 test_dictviews passes. -- Added file: http://bugs.python.org/file31022/non-error-recursive-dictview-3.3.patch ___ Python tracker <http://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Ben North added the comment: New patch, fixing nit noted in msg193624: non-error-recursive-dictview-3.3-1.patch Otherwise same as previous non-error-recursive-dictview-3.3.patch -- Added file: http://bugs.python.org/file31025/non-error-recursive-dictview-3.3-1.patch ___ Python tracker <http://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Changes by Ben North : Added file: http://bugs.python.org/file31089/against-9bf89c909bd4-3.3-1.patch ___ Python tracker <http://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Ben North added the comment: I'll attach fresh patches, one against latest 2.7 and one against latest 3.3 (unchanged apart from headers from previous patch). Both branches pass ./python -m test.regrtest -R20:30 test_dictviews -- ___ Python tracker <http://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Changes by Ben North : Added file: http://bugs.python.org/file31088/against-6e1dd1ce95b8-2.7-1.patch ___ Python tracker <http://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue18533] Avoid error from repr() of recursive dictview
Ben North added the comment: Is anything further needed from me before this can be reviewed? -- ___ Python tracker <http://bugs.python.org/issue18533> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5821] Documentation: mention 'close' and iteration for tarfile.TarFile.extractfile()
New submission from Ben North : The current documentation for tarfile.TarFile.extractfile() does not mention that the returned 'file-like object' supports close() and also iteration. The attached patch (against svn trunk) fixes this. (Background: I was wondering whether I could write def process_and_close_file(f_in): with closing(f_in) as f: # Do stuff with f. and have it work whether f_in was a true file or the return value of extractfile(), and thought from the documentation that I couldn't. Of course, I could have just tried it, but I think fixing the documentation wouldn't hurt.) -- assignee: georg.brandl components: Documentation files: tarfile.rst.patch keywords: patch messages: 86366 nosy: bennorth, georg.brandl severity: normal status: open title: Documentation: mention 'close' and iteration for tarfile.TarFile.extractfile() type: feature request Added file: http://bugs.python.org/file13749/tarfile.rst.patch ___ Python tracker <http://bugs.python.org/issue5821> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com