This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年07月27日 19:26 by rhettinger, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| none_bool.diff | rhettinger, 2011年07月27日 20:33 | Py3.3 patch | review | |
| Messages (7) | |||
|---|---|---|---|
| msg141269 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2011年07月27日 19:26 | |
Currently bool(None) returns False only because it has a special case in PyObject_IsTrue(). All other types can become False only if they implement __bool__() or __len__(). I propose removing the special case branch and instead adding __bool__ to None. This will simplify the explanation of what bool() does to: "bool(x) always returns True unless the object defines __bool__() to return False or defines __len__() to return a non-zero value". The removal of the special case will slightly slow down tests for "if None", and it will slightly speed-up tests for "if x" where x is something other than True, False, or None. |
|||
| msg141279 - (view) | Author: Brett Cannon (brett.cannon) * (Python committer) | Date: 2011年07月27日 22:05 | |
It all sounds good to me. Less magic behind the scenes is good. |
|||
| msg141280 - (view) | Author: Eric Snow (eric.snow) * (Python committer) | Date: 2011年07月27日 22:25 | |
And this doesn't impact "if x is None", so +1. |
|||
| msg141281 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2011年07月27日 22:27 | |
I'm not sure why the special case shouldn't be retained. It's obviously there for speed reasons. |
|||
| msg141282 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2011年07月27日 22:36 | |
> I'm not sure why the special case shouldn't be retained. We can keep the fast path in PyObject_IsTrue but add a __bool__ method to NoneType. |
|||
| msg141283 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2011年07月27日 22:37 | |
> > I'm not sure why the special case shouldn't be retained. > > We can keep the fast path in PyObject_IsTrue but add a __bool__ method to NoneType. That's what I meant. |
|||
| msg141308 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2011年07月28日 16:55 | |
New changeset ccce01988603 by Raymond Hettinger in branch 'default': Issue 12647: Add __bool__() method to the None object. http://hg.python.org/cpython/rev/ccce01988603 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:20 | admin | set | github: 56856 |
| 2011年07月28日 16:56:42 | rhettinger | set | status: open -> closed resolution: fixed |
| 2011年07月28日 16:55:29 | python-dev | set | nosy:
+ python-dev messages: + msg141308 |
| 2011年07月28日 16:05:32 | daniel.urban | set | nosy:
+ daniel.urban |
| 2011年07月27日 22:37:30 | pitrou | set | messages: + msg141283 |
| 2011年07月27日 22:36:51 | vstinner | set | nosy:
+ vstinner messages: + msg141282 |
| 2011年07月27日 22:27:58 | pitrou | set | nosy:
+ pitrou messages: + msg141281 |
| 2011年07月27日 22:25:17 | eric.snow | set | nosy:
+ eric.snow messages: + msg141280 |
| 2011年07月27日 22:05:40 | brett.cannon | set | nosy:
+ brett.cannon messages: + msg141279 |
| 2011年07月27日 20:33:05 | rhettinger | set | files:
+ none_bool.diff keywords: + patch |
| 2011年07月27日 19:26:16 | rhettinger | create | |