Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'syntax': 0.04; '"the': 0.07; '(all': 0.07; 'class,': 0.07; 'correspond': 0.09; 'function,': 0.09; 'obsolete': 0.09; 'subject:module': 0.09; 'trailing': 0.09; 'underscore': 0.09; 'wrong,': 0.09; 'python': 0.11; 'mostly': 0.14; '"official"': 0.16; 'methods;': 0.16; 'object):': 0.16; 'operators.': 0.16; 'reedy': 0.16; 'symbols': 0.16; 'variants': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'module': 0.19; '>>>': 0.22; 'import': 0.22; '(in': 0.22; 'email addr:gmail.com>': 0.22; 'to:name:python- list@python.org': 0.22; 'creating': 0.23; 'define': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'skip:p 30': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; "d'aprano": 0.31; 'names.': 0.31; 'operators': 0.31; 'steven': 0.31; 'class': 0.32; 'quite': 0.32; 'received:209.85.212': 0.32; 'table': 0.34; '"the': 0.34; "i'd": 0.34; 'received:209.85': 0.35; 'something': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'curious': 0.36; 'functions.': 0.36; 'module.': 0.36; 'shows': 0.36; 'should': 0.36; 'received:209': 0.37; 'being': 0.38; 'implement': 0.38; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'mapping': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'rather': 0.38; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'according': 0.40; 'how': 0.40; 'remove': 0.60; 'eventually': 0.60; '8bit%:10': 0.64; 'fact,': 0.69; 'special': 0.74; 'duplication': 0.84; 'etc,': 0.84; 'gelonida': 0.84; 'overloading': 0.84; 'do:': 0.91 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=ZRZR4EtIVMm2kA4xPn7SuJLyhfCu10mhZtlnN88vex8=; b=Bm9He+AJyIbYHyWIWLTXMbTzxeG7lZKlBFRTGCBrkuhJfS02FvGkSI5mkh99CUyiUf 37SC0c9XXIaxsN6zqAXsme0uQmkhBvDtyUCir736ZbkMElqWgnov1/HAPiq3Zqo08OUX WLkgCASZp1vgxuVDNb1F8xKj9Nq761X855U+sXyeZijcEXJ6m0U/xMNmZ20Hwuy4+7lz SRVLnt9SRjikePLcs7dMy5Pu7EzxG7RnPl2a5kAn4gzB/hvA1e5Bvw09OT6/LGC9Hyr4 zFuLZLxBDj59OEpANJKuvThYzfr8eKUDFdawDcjiUduo8wzj7JB3x4A9GQfFeap6+b1f esRA== X-Gm-Message-State: ALoCoQmTBdgUvwSK8RIaURJoWDbEbOQpO6Or2sVYKtMFmlipk5mV0glEETxdoqE3T9pPNuaxH05w X-Received: by 10.180.90.71 with SMTP id bu7mr218094wib.33.1412803305267; Wed, 08 Oct 2014 14:21:45 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <54349662$0$12987$c3e8da3$5496439d@news.astraweb.com> <543518a5$0$12989$c3e8da3$5496439d@news.astraweb.com> From: Chris Kaynor Date: Wed, 8 Oct 2014 14:21:25 -0700 Subject: Re: operator module functions To: "python-list@python.org" Content-Type: multipart/alternative; boundary=f46d043be0f42619950504efe709 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: 136 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1412804996 news.xs4all.nl 2885 [2001:888:2000:d::a6]:52456 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78855 --f46d043be0f42619950504efe709 Content-Type: text/plain; charset=UTF-8 On Wed, Oct 8, 2014 at 2:05 PM, Gelonida N wrote: > On 10/8/2014 9:09 PM, Terry Reedy wrote: > >> On 10/8/2014 6:57 AM, Steven D'Aprano wrote: >> >> According to the documentation, operator.__add__ is the "official" >>> function, >>> and operator.add is just there for convenience. >>> >> >> You are paraphrasing "The function names are those used for special >> class methods; variants without leading and trailing __ are also >> provided for convenience." But then there is the following: >> >> 10.3.1. Mapping Operators to Functions >> >> This table shows how abstract operations correspond to operator symbols >> in the Python syntax and the functions in the operator module. >> Operation Syntax Function >> Addition a + b add(a, b) >> >> etc, using the 'convenient' names. I would like to deprecate and >> eventually remove the dunder names. To me, the duplication is not >> 'convenient'. >> >> > > I'd be curious about a proposal to obsolete the double underscore > functions and just keep operator.add or to just keep the operator + > > For me they seem rather distinct, though they are interchangable in > certain situations. > > Perhaps I got something wrong, but all dunder functions are 'magic' > functions. Many of them mostly should ne used when when overloading > behaviour or when creating a class which should implement operators. > > print(dosomething(operator.add, 1, 2)) > print(dosomething(operator.add, a, b)) The thing being purposed to remove, is that you can also do: print(dosomething(operator.__add__, 1, 2)) print(dosomething(operator.__add__, a, b)) Not that fact that you can define __add__ in the class, or that "operator.add(a, b)" is the same as "a + b" (all of which are quite useful). Basically, the operator module has a "__add__" function in addition to a "add" function, and they are both identical (in fact, they are the same function object): >>> import operator >>> operator.add >>> operator.__add__ >>> operator.__add__ is operator.add True --f46d043be0f42619950504efe709 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On W= ed, Oct 8, 2014 at 2:05 PM, Gelonida N <gelonida@gmail.com>= wrote:
On 10/8/2014 = 9:09 PM, Terry Reedy wrote:
On 10/8/2014 6:57 AM, Steven D'Aprano wrote:

According to the documentation, operator.__add__ is the "official"= ;
function,
and operator.add is just there for convenience.

You are paraphrasing "The function names are those used for special class methods; variants without leading and trailing __ are also
provided for convenience."=C2=A0 But then there is the following:

10.3.1. Mapping Operators to Functions

This table shows how abstract operations correspond to operator symbols
in the Python syntax and the functions in the operator module.
Operation=C2=A0 =C2=A0 =C2=A0Syntax=C2=A0 =C2=A0 =C2=A0Function
Addition=C2=A0 =C2=A0 =C2=A0a + b=C2=A0 =C2=A0 =C2=A0add(a, b)

etc, using the 'convenient' names. I would like to deprecate and eventually remove the dunder names.=C2=A0 To me, the duplication is not
'convenient'.



I'd be curious about a proposal to obsolete the double underscore funct= ions and just keep operator.add or to just keep the operator +

For me they seem rather distinct, though they are interchangable in certain= situations.

Perhaps I got something wrong, but all dunder functions are 'magic'= functions. Many of them mostly should ne used when when overloading behavi= our or when creating a class which should implement operators.

print(dosomething(operator.add, 1, 2))
print(dosomething(operator.add, a, b))

The thing being purposed to remove, is that you can also do:
<= br>
print(dosomething(operator.__add__, 1, 2))
print(do= something(operator.__add__, a, b))

Not that= fact that you can define __add__ in the class, or that "operator.add(= a, b)" is the same as "a + b" (all of which are quite useful= ).

Basically, the operator module has a "__ad= d__" function in addition to a "add" function, and they are = both identical (in fact, they are the same function object):
>>> import operator
>>> operator.add
<built-in function add>
>>> operator.__add__
<built-in function add>
>>> operator.__add__= is operator.add
True

=C2=A0
=
--f46d043be0f42619950504efe709--