Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 preparation: Py3 has no more the special object-function "__nonzero__" #16076

Closed
wluebbe mannequin opened this issue Apr 7, 2014 · 22 comments
Closed

Python 3 preparation: Py3 has no more the special object-function "__nonzero__" #16076

wluebbe mannequin opened this issue Apr 7, 2014 · 22 comments

Comments

@wluebbe
Copy link
Mannequin

wluebbe mannequin commented Apr 7, 2014

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 meta-ticket ticket:16052.

CC: @embray

Component: python3

Issue created by migration from https://trac.sagemath.org/ticket/16076

@wluebbe wluebbe mannequin added this to the sage-6.2 milestone Apr 7, 2014
@wluebbe wluebbe mannequin added c: distribution labels Apr 7, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@jdemeyer

This comment has been minimized.

@fchapoton
Copy link
Contributor

comment:4

one step done (for the rings folder) in #21887

@fchapoton fchapoton modified the milestones: sage-6.4, sage-7.5 Nov 17, 2016
@fchapoton
Copy link
Contributor

comment:5

another step in #21898

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@fchapoton fchapoton modified the milestones: sage-7.5, sage-7.6 Jan 12, 2017
@fchapoton
Copy link
Contributor

comment:9

Here is a brute-force tentative

  • search and replace __nonzero__ by __bool__
  • remove the former lines that have become __bool__ = __bool__

Let us see what happens..


New commits:

5c0ed27substitute `__nonzero__` by __bool__
fbf00d7cleanup : removal of former alias for __nonzero__

@fchapoton
Copy link
Contributor

Commit: fbf00d7

@fchapoton
Copy link
Contributor

Branch: u/chapoton/16076

@fchapoton
Copy link
Contributor

comment:10

ok, this was too brutal.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 25, 2017

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

d3182dbtrac 16076 trying to get rid of the last nonzero

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 25, 2017

Changed commit from fbf00d7 to d3182db

@fchapoton
Copy link
Contributor

comment:12

ok, still not subtle enough..

@tscrim
Copy link
Collaborator

tscrim commented Jan 25, 2017

comment:13

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__()

@fchapoton
Copy link
Contributor

comment:14

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).

@tscrim
Copy link
Collaborator

tscrim commented Jan 25, 2017

comment:15

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.

@fchapoton
Copy link
Contributor

Changed branch from u/chapoton/16076 to none

@fchapoton
Copy link
Contributor

Changed commit from d3182db to none

@fchapoton fchapoton modified the milestones: sage-7.6, sage-8.0 Apr 6, 2017
@embray embray removed this from the sage-8.0 milestone Nov 23, 2017
@embray embray added the pending label Nov 23, 2017
@fchapoton
Copy link
Contributor

comment:18

why sage-pending ?

@embray
Copy link
Contributor

embray commented Nov 23, 2017

comment:19

I might be misusing the milestone but this seems to be a very general task ticket not tied to a specific release milestone...?

@fchapoton
Copy link
Contributor

comment:20

is this fixed by #24294?

@jdemeyer
Copy link

comment:21

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 in SageObject, 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

@embray
Copy link
Contributor

embray commented Nov 29, 2017

comment:22

Replying to @fchapoton:

is this fixed by #24294?

I don't think so by itself--I believe I've found some other examples affected by this (in non-Cython modules) but I could be mistaken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants