Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Descriptors vs Property Date: Fri, 11 Mar 2016 23:37:11 -0700 Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de PQP1s3tT9J6BopF6gxh+HwMIjZsjiHb+WPLa2X2Lrwzw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'value,': 0.03; 'resulting': 0.04; 'false.': 0.07; 'type,': 0.07; '"default': 0.09; 'typeerror:': 0.09; 'instead.': 0.15; '10:59': 0.16; '2016': 0.16; 'assumptions': 0.16; 'evaluates': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'unwarranted': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'otherwise,': 0.20; 'meant': 0.22; 'arguments': 0.22; 'parameter': 0.22; 'pass': 0.22; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'possibility': 0.27; 'message-id:@mail.gmail.com': 0.27; 'arguments,': 0.29; 'gets': 0.35; 'gives': 0.35; 'received:google.com': 0.35; 'instance': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'whatever': 0.39; 'does': 0.39; 'takes': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'default': 0.61; 'great': 0.63; 'mar': 0.65; 'account': 0.66; 'presumably': 0.84; 'shadows': 0.84; 'to:name:python': 0.84; 'subject:Property': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=IdhMqamYEfbBcpmSQFvtr5DJAVGBYod5WB/kyPjTZKo=; b=BBdWPSL+KNVncAb0ctCIb0q69Ao9tdIyUjHu2xcrREKKWbelwe9+zM6+lxVQ2voMmO UHIGLhT/8opwUUJ9e2YO/R0A3zna0Wlj9wBJbuMgwdwbbxb/YsoTpHYP52tRdoSmKmyC sdkm50CEDKx6IoV9Yq9cDaySTLsHGBanAZRvb4QvOGvYUGHgIR3P5UAk6mvG6x5Z+Sqj +U8F8rhWJQZNBqJ5eIwS+qSEY4nE49bdHHP2nqTv00Ypp/rd4O9QAk2ABAQZgXKWyf1q 6sz1C/H7d5pOah187WlmgJlhn8W0KS5lLfek/CuvON81WVZ1pViQt4QZcQg4GqaTBGKI seGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=IdhMqamYEfbBcpmSQFvtr5DJAVGBYod5WB/kyPjTZKo=; b=Yphx84lAgig0PmdkH5uqLObK1Kx2QxdP+lsg+QMKd8jM6w1XOfXuNYZtZ8e+NU4HZU ZTiLUXofYt41XKcgR1Z7jrKkrxD+paPfGOlODdzRvHIHKKqA7JXxRc7Zmqe35tVTH2yQ JwODvAi2DnVz3i2zPS2BsWNQzase1Xw3PH5u3kdIAuxAB1mnQ493soj6ws3+j6l3qy0l 71hAMwe+Ylh/kQ3sc+8oxohCeTPFb/PUqy89f8W3HwzsFFCkAmMMzb9XpzIeCLv4p0eD kmN1U5OUqHtF2bRWytSiR8pN1h3JeRomAsXROqYxx79u0J9zpph/oi/q4RdHAvSNWzIx cOcw== X-Gm-Message-State: AD7BkJKYGbVBe0RiCf23X9cTviEVEVCKuv7DNy/C+4UG1+OZWpopkUbI4QyA7T4ShZyh+bpwJzs+x7OyVveDSw== X-Received: by 10.50.131.201 with SMTP id oo9mr7783801igb.68.1457764670509; Fri, 11 Mar 2016 22:37:50 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104677 On Fri, Mar 11, 2016 at 11:24 PM, Veek. M wrote: > Ian Kelly wrote: > >> On Fri, Mar 11, 2016 at 10:59 PM, Veek. M wrote: >>> Also, what's this bit: >>> self.default = default if default else type() >> >> If the default parameter has a truthy value, it gets set to >> self.default. Otherwise, the type parameter is called with no >> arguments, and the resulting instance is used as self.default instead. > > But type() just gives me: > TypeError: type() takes 1 or 3 arguments > on py2,3 You're using the built-in type. In the example, type is the name of one of the arguments, so its value is whatever was passed in. Presumably it's meant to be the type that is being checked, and the result of calling it with no arguments is meant to be a default instance of that type. This is not a particularly great example, to be honest. It shadows a builtin, it makes unwarranted assumptions about the passed-in type, and the "default if default else type()" expression does not account for the possibility that the user might actually want to pass in a default that evaluates as false.