Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'only,': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:module': 0.09; 'python': 0.11; 'jan': 0.12; '"official"': 0.16; '(lambda': 0.16; '540': 0.16; 'forth.': 0.16; 'hits': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'stdlib.': 0.16; 'wrote:': 0.18; '(not': 0.18; 'bit': 0.19; 'seems': 0.21; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'versions': 0.24; 'header:X-Complaints-To:1': 0.27; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'gives': 0.31; "skip:' 10": 0.31; 'that.': 0.31; '1.4': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'anyone': 0.31; 'quite': 0.32; 'core': 0.34; 'there': 0.35; 'version': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'according': 0.40; 'skip:u 10': 0.60; 'course.': 0.60; 'most': 0.60; '"gt":': 0.84; '"lt":': 0.84; 'prefers': 0.84; 'received:fios.verizon.net': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: operator module functions Date: Wed, 08 Oct 2014 02:28:57 -0400 References: <54349662$0$12987$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: <54349662$0$12987$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1412749755 news.xs4all.nl 2969 [2001:888:2000:d::a6]:47930 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78826 On 10/7/2014 9:41 PM, Steven D'Aprano wrote: > Every Python operator has a function version in the operator module: > > operator + has function operator.add; > operator - has function operator.sub; > operator * has function operator.mul; > > and so forth. Only, that's not quite right... according to the > documentation, the "official" functions are actually: > > operator.__add__; > operator.__sub__; > operator.__mul__; > > etc., with the underscore-less versions being provided as a convenience. > > Was anyone aware of this? Of course. It has bugged me a bit for years. Messy. > Is there anyone who uses or prefers the dunder versions? I don't and don't, and that seems to be true of other core devs: there are no non-test uses of the dunder methods in the stdlib. Grepping /lib/*.py recursively for 'operator.' gives 540 hits, most for operator.someop. Grepping the same for 'operator.__' returns 4 hits for operator.__name__ and .__doc__ (not operators) and these 6 tests: C:\Programs\Python34\Lib\test\test_richcmp.py: 88: "lt": (lambda a,b: a< b, operator.lt, operator.__lt__), C:\Programs\Python34\Lib\test\test_richcmp.py: 89: "le": (lambda a,b: a<=b, operator.le, operator.__le__), C:\Programs\Python34\Lib\test\test_richcmp.py: 90: "eq": (lambda a,b: a==b, operator.eq, operator.__eq__), C:\Programs\Python34\Lib\test\test_richcmp.py: 91: "ne": (lambda a,b: a!=b, operator.ne, operator.__ne__), C:\Programs\Python34\Lib\test\test_richcmp.py: 92: "gt": (lambda a,b: a> b, operator.gt, operator.__gt__), C:\Programs\Python34\Lib\test\test_richcmp.py: 93: "ge": (lambda a,b: a>=b, operator.ge, operator.__ge_ If there a back-compatibility excuse? I cannot remember what operator had in 1.4 or whenever it was added, if after that. -- Terry Jan Reedy