Opened 7 years ago
Closed 3 years ago
#16076 closed enhancement (wontfix)
Python 3 preparation: Py3 has no more the special objectfunction "__nonzero__"
Reported by:  wluebbe  Owned by:  

Priority:  major  Milestone:  sageduplicate/invalid/wontfix 
Component:  python3  Keywords:  python3 
Cc:  embray  Merged in:  
Authors:  Reviewers:  
Report Upstream:  N/A  Work issues:  
Branch:  Commit:  
Dependencies:  Stopgaps: 
Description (last modified by )
The tool 2to3 renames __nonzero__
to __bool__
.
But the code has to depend on the Python version!
Note that this does not affect Cython extension types because Cython supports __nonzero__
and __bool__
independently of the Python version.
There are 25 affected modules.
This ticket is tracked as a dependency of metaticket ticket:16052.
Change History (23)
comment:1 Changed 7 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:2 Changed 7 years ago by
 Milestone changed from sage6.3 to sage6.4
comment:3 Changed 5 years ago by
 Component changed from distribution to python3
 Description modified (diff)
comment:4 Changed 4 years ago by
 Milestone changed from sage6.4 to sage7.5
comment:5 Changed 4 years ago by
another step in #21898
comment:6 Changed 4 years ago by
 Description modified (diff)
comment:7 Changed 4 years ago by
 Description modified (diff)
comment:8 Changed 4 years ago by
 Milestone changed from sage7.5 to sage7.6
comment:9 Changed 4 years ago by
 Branch set to u/chapoton/16076
 Commit set to fbf00d716c92c3f15ca9aed888817d5efa2b89b9
comment:10 Changed 4 years ago by
ok, this was too brutal.
comment:11 Changed 4 years ago by
 Commit changed from fbf00d716c92c3f15ca9aed888817d5efa2b89b9 to d3182db09b24647c2bde5ae5cf459afdbd58828d
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
d3182db  trac 16076 trying to get rid of the last nonzero

comment:12 Changed 4 years ago by
ok, still not subtle enough..
comment:13 followup: ↓ 21 Changed 4 years ago by
The way I've seen for this to be 2/3 compatible is to have __bool__
be an alias for __nonzero__
(or vice versa). The other way we could hack this is have in SageObject
, as almost everything has this as a base class, we implement:
def __bool__(self): return self.__nonzero__()
comment:14 Changed 4 years ago by
Hello Travis,
if you feel like giving it a try, please do. There is an abstract method __nonzero__
somewhere, which is the last place where __nonzero__
is not an alias (in python files).
comment:15 Changed 4 years ago by
I think we should keep things as __nonzero__
for right now (up to having an explicit alias) for right now since we are in Python2 and to avoid the extra redirection. Although I guess to test how much this would cover things for Python3, it would have to be with a Python3 build.
comment:16 Changed 4 years ago by
 Branch u/chapoton/16076 deleted
 Commit d3182db09b24647c2bde5ae5cf459afdbd58828d deleted
 Milestone changed from sage7.6 to sage8.0
comment:17 Changed 3 years ago by
 Milestone changed from sage8.0 to sagepending
comment:18 Changed 3 years ago by
why sagepending ?
comment:19 Changed 3 years ago by
I might be misusing the milestone but this seems to be a very general task ticket not tied to a specific release milestone...?
comment:20 followup: ↓ 22 Changed 3 years ago by
 Cc embray added
 Milestone changed from sagepending to sageduplicate/invalid/wontfix
 Status changed from new to needs_review
is this fixed by #24294?
comment:21 in reply to: ↑ 13 Changed 3 years ago by
 Status changed from needs_review to positive_review
Replying to tscrim:
The way I've seen for this to be 2/3 compatible is to have
__bool__
be an alias for__nonzero__
(or vice versa). The other way we could hack this is have inSageObject
, as almost everything has this as a base class, we implement:def __bool__(self): return self.__nonzero__()
I know that this reply is pointless is now, but I guess that something like that would have worked :)
We are doing something similar for division in CategoryObject
:
from __future__ import division cdef class CategoryObject(SageObject): def __div__(self, other): return self / other
comment:22 in reply to: ↑ 20 Changed 3 years ago by
comment:23 Changed 3 years ago by
 Resolution set to wontfix
 Status changed from positive_review to closed
one step done (for the rings folder) in #21887