Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue6428] TypeError: __bool__ should return bool or int, returned int

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jul 6, 2009, 7:45 AM

Post #1 of 6 (421 views)
Permalink
[issue6428] TypeError: __bool__ should return bool or int, returned int

New submission from SilentGhost <michael.mischurow+bpo [at] gmail>:

According to docs
(http://docs.python.org/3.1/reference/datamodel.html#object.__bool__)
__bool__ can return 1 or 0 instead of True or False.
However, when I ran the following code:

Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit
(Intel)] on win32
>>> class Spam():
def __bool__(self):
return 1


>>> if Spam():
print('ham')

I got the following error:

Traceback (most recent call last):
File "<pyshell#72>", line 1, in <module>
if Spam():
TypeError: __bool__ should return bool or int, returned int

So, do I misunderstand the docs or is it an error in them?

----------
assignee: georg.brandl
components: Documentation, Interpreter Core
messages: 90181
nosy: SilentGhost, georg.brandl
severity: normal
status: open
title: TypeError: __bool__ should return bool or int, returned int
type: behavior
versions: Python 3.1

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6428>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 6, 2009, 12:40 PM

Post #2 of 6 (383 views)
Permalink
[issue6428] TypeError: __bool__ should return bool or int, returned int [In reply to]

Antoine Pitrou <pitrou [at] free> added the comment:

It's not only the docs, the error message is self-contradictory as well.

----------
assignee: georg.brandl ->
nosy: +pitrou
priority: -> normal
stage: -> needs patch
versions: +Python 3.2

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6428>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 6, 2009, 3:50 PM

Post #3 of 6 (383 views)
Permalink
[issue6428] TypeError: __bool__ should return bool or int, returned int [In reply to]

Amaury Forgeot d'Arc <amauryfa [at] gmail> added the comment:

Probably a misguided merge. Here is a patch that updates the error
message, and the documentation.

----------
keywords: +needs review, patch
nosy: +amaury.forgeotdarc
Added file: http://bugs.python.org/file14460/bool.patch

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6428>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 6, 2009, 3:50 PM

Post #4 of 6 (386 views)
Permalink
[issue6428] TypeError: __bool__ should return bool or int, returned int [In reply to]

Changes by Amaury Forgeot d'Arc <amauryfa [at] gmail>:


----------
stage: needs patch -> patch review

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6428>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 6, 2009, 4:42 PM

Post #5 of 6 (392 views)
Permalink
[issue6428] TypeError: __bool__ should return bool or int, returned int [In reply to]

Eric Smith <eric [at] trueblade> added the comment:

The patch looks good to me. In particular, removing the test for
using_len looks correct.

The assignment of "result = -1" after PyErr_Format isn't needed, but
doesn't hurt (and it was already there, anyway).

----------
keywords: -needs review
nosy: +eric.smith

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6428>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jul 6, 2009, 5:45 PM

Post #6 of 6 (376 views)
Permalink
[issue6428] TypeError: __bool__ should return bool or int, returned int [In reply to]

Amaury Forgeot d'Arc <amauryfa [at] gmail> added the comment:

fixed in r73868 (py3k) and r73869 (3.1)
Thanks for the report!

----------
resolution: -> fixed
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue6428>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.