Equivalent code to the bool() built-in function

Ben Finney ben+python at benfinney.id.au
Sun Apr 17 04:39:54 CEST 2011


candide <candide at free.invalid> writes:

> Le 16/04/2011 23:13, Ben Finney a écrit :
>
> > The ‘bool’ built-in is not a function.
>
> Oops, unfortunate confusion!! but built-in types and built-in
> functions are sometimes so similar from the user's point of view ;)

Yes, intentionally so, because:

> All the same, you can notice that the official documentation describes
> bool() as a built-in function, cf.
> http://docs.python.org/library/functions.html

sometimes functions are replaced by types, or vice versa, and the user
code doesn't have to know.

Sadly, the result can be that the documentation is sometimes out of date
with the implementation :-)


candide <candide at free.invalid> writes:

> Le 16/04/2011 23:38, Ben Finney a écrit :
>
> > So the answer to the OP's question is no: the function isn't
> > equivalent to the type,
>
> Can bool() type and [my example] bool_equivalent() function return
> different values ?

Why do you need to know? (I should have asked that question earlier.)

> > because the OP's ‘bool_equivalent’ function necessarily uses the
> > built-in ‘bool’ type, while the reverse is not true.
>
> The documentation doesn't seem to state it performs this call.

Right, just as APIs that return strings won't explicitly talk about
calling the ‘str’ type constructor. I don't understand why you expect
that.

-- 
 \       “My business is to teach my aspirations to conform themselves |
  `\              to fact, not to try and make facts harmonise with my |
_o__)                   aspirations.“ —Thomas Henry Huxley, 1860-09-23 |
Ben Finney



More information about the Python-list mailing list