Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed1.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; '16,': 0.03; 'explicitly': 0.05; 'subject:Python': 0.06; 'args': 0.07; 'categories.': 0.09; 'separating': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'jan': 0.12; 'child.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'icon': 0.16; 'optional': 0.16; 'properties,': 0.16; 'reedy': 0.16; 'world",': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'possible,': 0.19; 'thu,': 0.19; 'widget': 0.19; 'saying': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'specify': 0.24; 'title,': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'properties': 0.29; 'matching': 0.30; 'message-id:@mail.gmail.com': 0.30; 'allows': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'maybe': 0.34; "i'd": 0.34; 'problem': 0.35; 'possible.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'keyword': 0.36; 'should': 0.36; 'error.': 0.37; 'two': 0.37; 'being': 0.38; 'button': 0.38; 'does': 0.39; 'either': 0.39; 'called': 0.40; 'back': 0.62; 'name': 0.63; 'real': 0.63; 'such': 0.63; 'happen': 0.63; 'size.': 0.65; 'worth': 0.66; 'potentially': 0.81; 'bitmap': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=22T1ZrNLeLbS5pYAfEQBn/AOPOB93OYsmn958c6vH3E=; b=XTagYDmFH7v45aL2C/VfTBMq+kDfp3FEmx0xmpqW/F8Uul914DVyx5j5i7agvCPoMJ TFFc0VS82qakcLqgrjmGXoh3uVXw8jQjC0VTEyJSdY7U8+1kJgkJN1HCPIKtqM7PX25Q KHyCco33Mp+uuBNFDNXojuEyM1cEGimwjrfmCPL6x/owvMPyjQz33w9XXT+thkf8SSrS IiYHJnyEZ+W/kmVyR4Q+VP0mVDiM867gj9R0pmrL0og/HkPIsd6TDrrPrg/5zI06STi4 d3GvBrNJNweKoRsfair1pQKqSS/RfkWhT6FX55Y4SOiIyO6G4Qxqfx3QWo3jltlKeM89 IQkA== MIME-Version: 1.0 X-Received: by 10.68.162.66 with SMTP id xy2mr5976575pbb.46.1389827387603; Wed, 15 Jan 2014 15:09:47 -0800 (PST) In-Reply-To: References: <1389805328.32401.6.camel@linux-fetk.site> Date: Thu, 16 Jan 2014 10:09:47 +1100 Subject: Re: Python declarative From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389827396 news.xs4all.nl 2840 [2001:888:2000:d::a6]:49560 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64024 On Thu, Jan 16, 2014 at 9:58 AM, Terry Reedy wrote: > class Window: > def __init__(self, title, *kwds) # or title='Window title' > self.title = title > self.__dict__.update(kwds) Does that want a second asterisk, matching the Button definition? >> Possible, but potentially messy; if you happen to name your button >> "icon", it might be misinterpreted as an attempt to set the window's >> icon, and cause a very strange and incomprehensible error. > > Puns are always a problem with such interfaces. Validate the args as much as > possible. An icon should be a bitmap of appropriate size. Optional args > should perhaps all be widgets (instances of a Widget baseclass). Yeah, but you'd still get back an error saying "icon should be a bitmap" where the real problem is "icon should be called something else". It might be worth explicitly adorning properties, or separating them into two categories. Since the keyword-named-children system has the other problem of being hard to lay out (how do you specify the order?), I'd look at keyword args for properties and something separate for children - either the layout I used above with .add(), which allows extra args as necessary, or something like this: myWindow = Window( title="Hello World", children=[Button( label="I'm a button", onClick=exit )] ) Or maybe allow "child=" as a shortcut, since a lot of widgets will have exactly one child. ChrisA