Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'suppose': 0.07; 'classes.': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'def': 0.12; 'mostly': 0.14; 'filename:fname piece:signature': 0.16; 'foo(object):': 0.16; 'lambda': 0.16; 'new-style': 0.16; 'old- style': 0.16; 'subject:when': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'looked': 0.18; 'bit': 0.19; 'header:User-Agent:1': 0.23; '2.x': 0.24; 'skip': 0.24; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'ignored.': 0.30; 'code': 0.31; 'object.': 0.31; 'class': 0.32; 'run': 0.32; 'skip:_ 10': 0.34; 'subject:from': 0.34; 'problem': 0.35; 'but': 0.35; 'charset:us- ascii': 0.36; 'changing': 0.37; 'list': 0.37; 'subject:new': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'anytime': 0.60; 'received:173': 0.61; 'more': 0.64; 'obvious': 0.74; 'subject:Potential': 0.91; 'serious': 0.97 Date: Wed, 19 Nov 2014 11:29:34 -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: Potential pitfalls when going from old-style to new-style classes References: In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="v8rcPNrKaTgnM1doSc6E3lTx37uBV9eAH" 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: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416425382 news.xs4all.nl 2914 [2001:888:2000:d::a6]:46985 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81038 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --v8rcPNrKaTgnM1doSc6E3lTx37uBV9eAH Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable On 11/19/2014 11:14 AM, Skip Montanaro wrote: > I discussion on the code-quality list got me thinking. Suppose I have > an old-style class in a 2.x app: >=20 > class Foo: > def __init__(self): > blah blah blah >=20 > I still use 2.x exclusively, but anytime I run pylint over a bit of > code and it complains that Foo is old-school, I make the obvious > change to inherit from object. While I do this mostly to shut up > pylint so I can focus on more serious messages, I must admit I have > never experienced any problem changing from old-style to new-style > classes. Under what circumstances might this be problematic? One problem is if your class has dunder methods on the instance -- they w= ill be ignored. class Foo(object): def __init__(self): self.__add__ =3D lambda : 'whatever' dunder methods are looked up on the class. -- ~Ethan~ --v8rcPNrKaTgnM1doSc6E3lTx37uBV9eAH 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) iQIcBAEBAgAGBQJUbO+hAAoJENZ7D1rrH75N0ugQAMgrdCfUwigXf8+GHUM1zYEg bHYqbhaYd6sRWmbsUgtFbCrnoclM3WrH/UWAYQPHhcgFAGZ4INCYFLIpWiDkY6iJ +2YSgN+Ez6/IGacwEn1MuW3ZuXp0Ha9ZZMIGVfVtMvybTa8vsee+KQOv/qvdrdfM UoPBpCYIQwaCMUr4jyShUezG9F5Atok+/A8aPMnMjVZUVTNA1zKyqvyoFB+blbov DAPLr5r0SREkuuJy6a3MJgD6Ir7H8oMHJRSum5DFQICFuKp1Fqy9PN9L12ppHFDl PD71kT+xrDC42/cmMAr9hZ55fjOmlF1bwjmoDkKBH3KMMJ54OZAmtDZageEwztVK tk4K2oBzpL6wR43/I0SwmYeevKzGWL8aCR0ZuqYsv+mmESfvlcbqsqh319wG4m7r j1eQ90YBqFGgWAeRYTwuAKMum52l3D/ZVsSSQD+xPInfCeJJpgQMH3RGaYpXrrEY VcoUWiCXsiAGW8zN83r2T8tur+AcrVL91f8UoE8iu1hEEx1OOaN+WfESoDtsKNaK nmVy12kPU/Mq6BSlczUMjq64htBgLyPZcD08cDsajXhKCrMGbPXWJTxwD1LQpNHd dSwiF8n0NkdhRMr6xeHpQNyIBdTCmUczspSAIRsmHmRzgsMLsDrqv24+wsQIvNpA w7s34Ibwq7v8MurLbRQy =4fnP -----END PGP SIGNATURE----- --v8rcPNrKaTgnM1doSc6E3lTx37uBV9eAH--