Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104677
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Descriptors vs Property |
| Date | 2016-03-11 23:37 -0700 |
| Message-ID | <mailman.28.1457764672.12893.python-list@python.org> (permalink) |
| References | <nc0b1u$ckq$1@dont-email.me> <mailman.26.1457763193.12893.python-list@python.org> <nc0cgs$fvn$2@dont-email.me> |
On Fri, Mar 11, 2016 at 11:24 PM, Veek. M <vek.m1234@gmail.com> wrote: > Ian Kelly wrote: > >> On Fri, Mar 11, 2016 at 10:59 PM, Veek. M <vek.m1234@gmail.com> 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-12 11:29 +0530
Re: Descriptors vs Property Chris Angelico <rosuav@gmail.com> - 2016-03-12 17:05 +1100
Re: Descriptors vs Property Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-11 23:12 -0700
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-12 11:54 +0530
Re: Descriptors vs Property Chris Angelico <rosuav@gmail.com> - 2016-03-12 17:35 +1100
Re: Descriptors vs Property Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-11 23:37 -0700
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-12 11:50 +0530
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-12 18:13 +0100
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-13 12:48 +0530
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-13 10:25 +0100
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-13 15:26 +0530
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-13 11:35 +0100
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-13 18:50 +0530
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-13 19:15 +0100
Re: Descriptors vs Property Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 15:34 +0000
Re: Descriptors vs Property Rustom Mody <rustompmody@gmail.com> - 2016-03-14 10:16 -0700
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-16 01:53 +0100
Re: Descriptors vs Property Ethan Furman <ethan@stoneleaf.us> - 2016-03-16 08:15 -0700
csiph-web