On Fri, Mar 11, 2016 at 11:24 PM, Veek. M <vek.m1...@gmail.com> wrote:
> Ian Kelly wrote:
>
>> On Fri, Mar 11, 2016 at 10:59 PM, Veek. M <vek.m1...@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.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to