Ask Your Question
1

Abstract base classes

asked 13 years ago

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

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
4

answered 13 years ago

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.

Preview: (hide)
link

Comments

Thanks for this very quick and precise answer

Bétréma gravatar imageBétréma ( 13 years ago )
0

answered 13 years ago

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.

Preview: (hide)
link

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 ( 13 years ago )

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: 13 years ago

Seen: 545 times

Last updated: Oct 01 '11