Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: can't add variables to instances of built-in classes Date: Wed, 20 Jul 2016 09:26:08 +0200 Organization: None Lines: 65 Message-ID: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: news.uni-berlin.de 2Kb2ZDHow/H8JVQ9v2cdGg3c0TERJuXUf+oU/Klh2/Rw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'context': 0.05; 'fixes': 0.05; 'imply': 0.07; 'wednesday,': 0.07; '__init__': 0.09; 'grep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple': 0.09; 'url:github': 0.09; 'def': 0.13; 'wed,': 0.15; '2016': 0.16; '__slots__': 0.16; 'accidental': 0.16; 'exactly?': 0.16; 'how,': 0.16; 'integer.': 0.16; 'properties,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'traceback.': 0.16; 'tuple,': 0.16; 'why,': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'debugging': 0.18; 'detect': 0.18; '>>>': 0.20; 'settings': 0.20; 'candidates': 0.21; 'work,': 0.21; 'lawrence': 0.22; 'trying': 0.22; 'am,': 0.23; 'defined': 0.23; 'all.': 0.24; 'sort': 0.25; 'wondering': 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'appear': 0.26; 'header:X-Complaints-To:1': 0.26; 'sense': 0.26; 'chris': 0.26; 'error': 0.27; 'cat': 0.29; 'that.': 0.30; "we're": 0.30; 'programmers': 0.30; "i'd": 0.31; 'fixed': 0.31; 'skip:_ 10': 0.32; 'class': 0.33; 'problem': 0.33; 'controls': 0.33; "i'll": 0.33; 'something': 0.35; 'problem.': 0.35; 'but': 0.36; 'instead': 0.36; 'lines': 0.36; 'monday,': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'say': 0.37; 'received:org': 0.37; 'thank': 0.38; 'why': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'called': 0.40; 'future': 0.60; 'email addr:gmail.com': 0.62; 'complete': 0.63; 'you.': 0.64; '20,': 0.66; '>>>>>': 0.66; 'skip:\xe2 10': 0.70; 'jul': 0.72; '8bit%:46': 0.76; 'sounds': 0.76; 'cult': 0.84; 'wasn\xe2\x80\x99t': 0.84; 'subject:add': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd86d9.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> <578b9e62$0$22141$c3e8da3$5496439d@news.astraweb.com> <3e934f83-2076-407d-b85b-686ecdec6ff8@googlegroups.com> <2bc29306-ac90-4424-84c2-64be494c5a75@googlegroups.com> <230d1aff-b1a3-4f16-b9a6-b5d9fd07e4b4@googlegroups.com> <62dd86d4-74f7-4e97-a29c-7e45aced77d9@googlegroups.com> Xref: csiph.com comp.lang.python:111665 Lawrence D’Oliveiro wrote: > On Wednesday, July 20, 2016 at 6:19:45 PM UTC+12, Chris Angelico wrote: >> >> On Wed, Jul 20, 2016 at 9:58 AM, Lawrence D’Oliveiro wrote: >>> >>> On Wednesday, July 20, 2016 at 9:24:57 AM UTC+12, bream...@gmail.com >>> wrote: >>>> >>>> On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D’Oliveiro >>>> wrote: >>>>> >>>>> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream...@gmail.com >>>>> wrote: >>>>>> >>>>>> On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D’Oliveiro >>>>>> wrote: >>>>>>> >>>>>>> >>>>>>> When you have lots of read/write properties, I find __slots__ to be >>>>>>> a good idea. >>>>>> >>>>>> Please explain why, thank you. >>>>> >>>>> I was trying something like >>>>> >>>>> ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) >>>>> >>>>> and wondering why it wasn’t working... >>>> >>>> This makes no sense to me at all. You appear to be trying to create a >>>> tuple, which contains a tuple and an integer. You then say it doesn't >>>> work, but imply that using __slots__ fixes the problem. So please >>>> explain exactly what you were trying to achieve, the exact error you >>>> got, with the complete traceback, and how using __slots__ fixed the >>>> problem. >>> >>> No traceback. The lines were simply coming out solid, instead of dashed. >> >> And __slots__ fixed the problem how, exactly? > > The Context attribute that controls the dash settings is called “dash”, > not “dashes”. > >> This sounds like the sort of cargo cult debugging that I'd expect of PHP >> programmers ("I put addslashes around everything and now it works, so in >> future I'll use addslashes everywhere"), but around here, we're better >> than that. > > OK, boss. pylint can detect candidates for accidental attribute creation: $ cat attrib.py class Context: def __init__(self): self.dashes = None ctx = Context() ctx.dasehs = ("foo", "bar") $ pylint attrib | grep dasehs W: 6, 4: Attribute 'dasehs' defined outside __init__ (attribute-defined- outside-init)