Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue33265

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:contextlib.ExitStack abuses __self__
Type:performanceStage:resolved
Components:Library (Lib)Versions:Python 3.8
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: jdemeyer, ncoghlan, yselivanov
Priority:normalKeywords:patch

Created on2018-04-12 05:24 byjdemeyer, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 6456mergedjdemeyer,2018-04-12 05:28
Messages (5)
msg315212 -(view)Author: Jeroen Demeyer (jdemeyer)*(Python triager)Date: 2018-04-12 05:24
In contextlib, there is code which roughly looks like        def _exit_wrapper(exc_type, exc, tb):            return cm_exit(cm, exc_type, exc, tb)        _exit_wrapper.__self__ = cmThis creates a new function _exit_wrapper from a given function cm_exit by prepending the __self__ attribute to *args. Now this is exactly what a method does too.It would be better to use an actual method for this: it's cleaner, faster and it doesn't abuse a double-underscore attribute. The latter will actually break withPEP 575, as __self__ will become a special name  instead of an arbitrary attribute.
msg315221 -(view)Author: Alyssa Coghlan (ncoghlan)*(Python committer)Date: 2018-04-12 12:25
Yury, could you double check the async exit stack change in the PR? I think it's fine since the bound method just passes back the underlying coroutine and the tests all still pass, but a second opinion would be good :)
msg315239 -(view)Author: Yury Selivanov (yselivanov)*(Python committer)Date: 2018-04-13 03:29
Yep, I think this is a good fix!
msg315243 -(view)Author: Alyssa Coghlan (ncoghlan)*(Python committer)Date: 2018-04-13 12:22
New changeset23ab5ee667a9b29014f6f7f01797c611f63ff743 by Nick Coghlan (jdemeyer) in branch 'master':bpo-33265: use an actual method instead of a method-like function in ExitStack (GH-6456)https://github.com/python/cpython/commit/23ab5ee667a9b29014f6f7f01797c611f63ff743
msg315244 -(view)Author: Alyssa Coghlan (ncoghlan)*(Python committer)Date: 2018-04-13 12:25
Classifying this as a minor performance enhancement, since methods are much simpler objects than full Python level closures.Thanks!
History
DateUserActionArgs
2022-04-11 14:58:59adminsetgithub: 77446
2018-04-13 12:25:09ncoghlansetstatus: open -> closed
versions: + Python 3.8
type: performance
messages: +msg315244

resolution: fixed
stage: patch review -> resolved
2018-04-13 12:22:50ncoghlansetmessages: +msg315243
2018-04-13 03:29:00yselivanovsetmessages: +msg315239
2018-04-12 12:25:27ncoghlansetnosy: +yselivanov
messages: +msg315221
2018-04-12 06:40:24eric.smithsetnosy: +ncoghlan
2018-04-12 05:28:43jdemeyersetkeywords: +patch
stage: patch review
pull_requests: +pull_request6151
2018-04-12 05:24:51jdemeyercreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp