ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 02 Oct 2011 13:47:24 +0200Abstract base classeshttps://ask.sagemath.org/question/8352/abstract-base-classes/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).Fri, 30 Sep 2011 14:12:06 +0200https://ask.sagemath.org/question/8352/abstract-base-classes/Answer by Mike Hansen for <p>Python has a module named abc for implementing "abstract base classes", see <a href="http://www.python.org/dev/peps/pep-3119/">http://www.python.org/dev/peps/pep-3119/</a> for definitions and usage. Why is it not used in Sage ?</p>
<p>Example: if type(i) is 'int', isinstance (i, Integer) should be True (today it's False).</p>
https://ask.sagemath.org/question/8352/abstract-base-classes/?answer=12710#post-id-12710One 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.Fri, 30 Sep 2011 14:50:47 +0200https://ask.sagemath.org/question/8352/abstract-base-classes/?answer=12710#post-id-12710Comment by Bétréma for <p>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 <code>isinstance(i, Integer)</code> to be <code>True</code> since in Sage <code>Integer</code> is a concrete class wrapping an MPIR <code>mpz_t</code>. However, you could register <code>Integer</code> as <code>numbers.Integral</code> and then test against that.</p>
https://ask.sagemath.org/question/8352/abstract-base-classes/?comment=21179#post-id-21179Thanks for this very quick and precise answerSat, 01 Oct 2011 13:22:38 +0200https://ask.sagemath.org/question/8352/abstract-base-classes/?comment=21179#post-id-21179Answer by Bétréma for <p>Python has a module named abc for implementing "abstract base classes", see <a href="http://www.python.org/dev/peps/pep-3119/">http://www.python.org/dev/peps/pep-3119/</a> for definitions and usage. Why is it not used in Sage ?</p>
<p>Example: if type(i) is 'int', isinstance (i, Integer) should be True (today it's False).</p>
https://ask.sagemath.org/question/8352/abstract-base-classes/?answer=12711#post-id-12711So, 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.Sat, 01 Oct 2011 13:40:41 +0200https://ask.sagemath.org/question/8352/abstract-base-classes/?answer=12711#post-id-12711Comment by Volker Braun for <p>So, it seems that in many situations we have to code <code>if isinstance (n, (int, Integer))</code> instead of <code>if isinstance (n, Integer)</code>, despite the fact that the latter is much more natural. Sigh.</p>
https://ask.sagemath.org/question/8352/abstract-base-classes/?comment=21176#post-id-21176Right 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.Sun, 02 Oct 2011 13:47:24 +0200https://ask.sagemath.org/question/8352/abstract-base-classes/?comment=21176#post-id-21176