Ask Your Question
1

Abstract base classes

asked 2011-09-30 14:12:06 +0100

Python has a module named abc for implementing "abstract base classes", see http://www.python.org/dev/peps/pep-3119/ for definitions and usage. Why is it not used in Sage ?

Example: if type(i) is 'int', isinstance (i, Integer) should be True (today it's False).

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
4

answered 2011-09-30 14:50:47 +0100

Mike Hansen gravatar image

One reason is that abstract base classes are relatively new (Python 2.6) and the work hasn't been done to put them in place. It will require a bit of thought about how best to use them within Sage. For example, I don't think we want isinstance(i, Integer) to be True since in Sage Integer is a concrete class wrapping an MPIR mpz_t. However, you could register Integer as numbers.Integral and then test against that.

edit flag offensive delete link more

Comments

Thanks for this very quick and precise answer

Bétréma gravatar imageBétréma ( 2011-10-01 13:22:38 +0100 )edit
0

answered 2011-10-01 13:40:41 +0100

So, it seems that in many situations we have to code if isinstance (n, (int, Integer)) instead of if isinstance (n, Integer), despite the fact that the latter is much more natural. Sigh.

edit flag offensive delete link more

Comments

Right now, isinstance (n,Integer) is used to check whether Cython code can directly access the wrapped gmp integer. Changing this would just move the instance checks around, but not really simplify anything.

Volker Braun gravatar imageVolker Braun ( 2011-10-02 13:47:24 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-09-30 14:12:06 +0100

Seen: 521 times

Last updated: Oct 01 '11