Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.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; 'syntax': 0.04; 'subject:Python': 0.06; 'diff': 0.07; 'level,': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'operand': 0.09; '~ethan~': 0.09; 'python': 0.11; 'differs': 0.16; 'filename:fname piece:signature': 0.16; "operand's": 0.16; 'other,': 0.16; 'subclass': 0.16; 'appropriate': 0.16; 'student': 0.16; 'wrote:': 0.18; '(the': 0.22; 'programming': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; '(such': 0.24; 'documented': 0.24; '(or': 0.24; 'possibly': 0.26; 'this:': 0.26; 'header:In- Reply-To:1': 0.27; 'asked': 0.31; 'didnt': 0.31; 'class': 0.32; 'cases': 0.33; 'moment': 0.34; 'subject: (': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'surely': 0.36; 'method': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'little': 0.38; 'to:addr:python.org': 0.39; 'received:173': 0.61; 'simple': 0.61; "you're": 0.61; 'first': 0.61; 'complete': 0.62; 'skip:n 10': 0.64; 'more': 0.64; 'between': 0.67; 'dont': 0.67; 'subject:! ': 0.74; 'subject:!)': 0.84; 'surface': 0.84; 'directly.': 0.95 Date: Sun, 01 Feb 2015 00:12:10 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: dunder-docs (was Python is DOOMED! Again!) References: <54c07d04$0$13012$c3e8da3$5496439d@news.astraweb.com> <35a40ec6-3763-448b-9ea4-4a233a04979b@googlegroups.com> <54c1ccc8$0$13005$c3e8da3$5496439d@news.astraweb.com> <54c6d7c2$0$12992$c3e8da3$5496439d@news.astraweb.com> <54c83ab4$0$12982$c3e8da3$5496439d@news.astraweb.com> <54ca583e$0$13005$c3e8da3$5496439d@news.astraweb.com> <54ccc2fc$0$13009$c3e8da3$5496439d@news.astraweb.com> <54cd9a7a$0$12984$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="t5x1I3rGJI3i39Am0wIOIV9HuxGaM4aK8" 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: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422778368 news.xs4all.nl 2842 [2001:888:2000:d::a6]:34534 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84990 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --t5x1I3rGJI3i39Am0wIOIV9HuxGaM4aK8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 01/31/2015 09:36 PM, Rustom Mody wrote: >=20 > And a student asked me the diff between > dir([]) > and > [].__dir__() >=20 > I didnt know what to say... > Now surely the amount of python I dont know is significantly larger tha= n what I know > Still it would be nice to have surface-syntax =E2=86=90=E2=86=92 dunder= -magic more > systematically documented I don't have a complete answer for you, but I can say this: In simple cases (such as __len__) there is little difference between call= ing the surface operator and the dunder version (the error message differs in this case). In more complex cases (such as __add__) using the surface syntax (+) buys= lots of extras: - if one operand is a subclass of the other, calling its __add__ or __r= add__ method as appropriate - if the first operand returns NotImplemented, calling the other operan= d's __radd__ to see if that works - possibly others that I don't recall at the moment Basically, unless you're programming at the system (or class internals) l= evel, don't call dunder methods directly. -- ~Ethan~ --t5x1I3rGJI3i39Am0wIOIV9HuxGaM4aK8 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAEBAgAGBQJUzd/dAAoJENZ7D1rrH75NRSAP/10fO5cFt6GDckeTK6kHvQO4 qzrlcSA6zRaqxVqTd/6cQ9OG/AE3pGnEgunG/zWjHEyW0qNP4N58hSGPG8OtI/OE Q5HF5eUVjYgK7ZcVn1o3YlhqCc3klhDKWfa5iituwufbLaQ2jK4QzXu9eYHmzjOh w+u3vnH98ul4zG+qX96nYFj8QZeXNgt6mSdAWwxsGCVofIXQuOw7NuZS94xbP+gy wJzNs2Hd2LD4lwflPxLW9Gn9odqww3m93+3AT8oot8n6jaEBg5xTA/SmwSPFJRLg KFXo8xM+xeXqDJ1Uq/uhhetrtuPCBjrdDLdoklgAhDku0lk4GcjPmqErHceFY7xt 2hy3eXoWrponrbnIBg/tdiTaZ3015s3hFLclEEpx9M8HoOrPDiQVsfycIthEinzP uywjZt5WUyi2HzPcI5XUZ+I8G3SkBBHmZS+GOFV//IAfFzgs23yM98YWeAhgZ0nv zC2SJ2U9eH7kkZMTkOAAaHn7Qi4iKhk+Zh84dcJF1znFshed54GJOj768TcedO36 Dfg3e3po7Cp6rppM1p3jAtrxc3Um2cMH8blsRxLZTOyun4sZx/I3/8iAzemk7AC/ fl43PbP5ydVs5K0e+MojlGOMIvpr01gWBoe0Wg5w284RyhAs8jftIaHHwOH0T2BD i6IN+yb1R6O4BgsyxYHi =r+5v -----END PGP SIGNATURE----- --t5x1I3rGJI3i39Am0wIOIV9HuxGaM4aK8--