Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81038
| 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 | <ethan@stoneleaf.us> |
| 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 <ethan@stoneleaf.us> |
| 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 | <CANc-5UycmD0R9mN8JuBAjO86irMooAAzxWnfvyGvbnnfmpHaYA@mail.gmail.com> |
| In-Reply-To | <CANc-5UycmD0R9mN8JuBAjO86irMooAAzxWnfvyGvbnnfmpHaYA@mail.gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15998.1416425382.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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:
>
> class Foo:
> def __init__(self):
> blah blah blah
>
> 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 will be ignored.
class Foo(object):
def __init__(self):
self.__add__ = lambda : 'whatever'
dunder methods are looked up on the class.
--
~Ethan~
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Potential pitfalls when going from old-style to new-style classes Ethan Furman <ethan@stoneleaf.us> - 2014-11-19 11:29 -0800
csiph-web