Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue32380

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:functools.singledispatch interacts poorly with methods
Type:behaviorStage:resolved
Components:Library (Lib)Versions:Python 3.8
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: ethan smith, levkivskyi, lukasz.langa, methane, ncoghlan
Priority:normalKeywords:patch

Created on2017-12-19 22:23 byethan smith, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 4987closedethan smith,2017-12-23 07:12
PR 6306mergedethan smith,2018-03-29 10:38
PR 12580mergedmethane,2019-03-27 08:36
Messages (7)
msg308687 -(view)Author: Ethan Smith (ethan smith)*Date: 2017-12-19 22:23
Consider the following:from functools import singledispatchclass Dispatch:    @singledispatch    def foo(self, a):        return a    @foo.register(int)    def _(self, a):        return "int"    @foo.register(str)    def _(self, a):        return "str"cls = Dispatch()cls.foo(3)  # 3cls.foo('hm')  # 'hm'I find this quite unintuitive. Essentially, since singledispatch dispatches based solely on a functions first argument, it is useless on methods unless one wraps it and modifies how it uses the internal wrapper function. I believe this should be relatively easy to fix with adding a check of inspect.ismethod and then modifying the number of the checked argument where appropriate.I'm happy to write a patch if this change is seen as a good idea.
msg308944 -(view)Author: Ivan Levkivskyi (levkivskyi)*(Python committer)Date: 2017-12-22 23:53
I have also noticed this problem and I like the idea. It appeared some time ago on python-ideas, but no one has written a patch.
msg314644 -(view)Author: Alyssa Coghlan (ncoghlan)*(Python committer)Date: 2018-03-29 12:17
Added Łukasz to the nosy list, as I'd like his +1 before accepting this change (I do still think it's a good idea, for the same reasons we added partialmethod).
msg314817 -(view)Author: Łukasz Langa (lukasz.langa)*(Python committer)Date: 2018-04-02 17:40
+1
msg317765 -(view)Author: Łukasz Langa (lukasz.langa)*(Python committer)Date: 2018-05-26 20:38
New changesetc651275afe8515b2cf70b8152e19ce39df88f0dd by Łukasz Langa (Ethan Smith) in branch 'master':bpo-32380: Create functools.singledispatchmethod (#6306)https://github.com/python/cpython/commit/c651275afe8515b2cf70b8152e19ce39df88f0dd
msg317941 -(view)Author: Ethan Smith (ethan smith)*Date: 2018-05-28 22:47
This was fixed, so I think it can be closed.
msg338945 -(view)Author: Inada Naoki (methane)*(Python committer)Date: 2019-03-27 09:15
New changesetbc284f0c7a9a7a9a4bf12c680823023a6770ce06 by Inada Naoki in branch 'master':bpo-32380: add "versionadded: 3.8" to singledispatchmethod (GH-12580)https://github.com/python/cpython/commit/bc284f0c7a9a7a9a4bf12c680823023a6770ce06
History
DateUserActionArgs
2022-04-11 14:58:55adminsetgithub: 76561
2019-03-27 09:15:21methanesetnosy: +methane
messages: +msg338945
2019-03-27 08:36:17methanesetpull_requests: +pull_request12524
2018-05-28 22:47:25ethan smithsetstatus: open -> closed
resolution: fixed
messages: +msg317941

stage: patch review -> resolved
2018-05-26 20:38:36lukasz.langasetmessages: +msg317765
2018-04-02 17:40:29lukasz.langasetmessages: +msg314817
2018-03-29 12:17:13ncoghlansetnosy: +ncoghlan,lukasz.langa
messages: +msg314644
2018-03-29 10:44:13ethan smithsetversions: + Python 3.8, - Python 3.6
2018-03-29 10:38:40ethan smithsetpull_requests: +pull_request6024
2017-12-23 07:12:16ethan smithsetkeywords: +patch
stage: patch review
pull_requests: +pull_request4873
2017-12-22 23:53:47levkivskyisetnosy: +levkivskyi
messages: +msg308944
2017-12-19 22:23:08ethan smithcreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp