#18159: cardinality must output Infinty or a Sage integer
-------------------------------------+-------------------------------------
Reporter: vdelecroix | Owner:
Type: enhancement | Status: new
Priority: critical | Milestone: sage-6.6
Component: categories | Resolution:
Keywords: | Merged in:
Authors: Vincent Delecroix | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/vdelecroix/18159 | e40975a50978d76bf1c8ad4a141470dc0b010289
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by vdelecroix):
Replying to [comment:22 ncohen]:
> > It is not sufficient. '''You''' were arguing that Python ints were
better because faster. I just showed you that it is not completely right.
An argument for `X` is generally not an argument for `Y`.
>
> All I wanted to point out is that *sometimes* an int is better than an
Integer, and that for this reason they should not be forbidden. I do not
mean to say that a Python int is always better than a Sage Integer, and
quite clearly it is not the case: ints overflows, Integers do not.
Just to be sure: I do not want to forbid Python integer in general. For
the output of `.cardinality()` I consider that Sage integers are *always*
better. Perhaps I am wrong and this can be debated if needed. And, as I
already mentioned, you can get Python integer for less effort doing
`len(my_set)`.
> > The reason to oblige people to return Sage integers or Infinity in the
method `.cardinality` of a `Parent` is mostly for consistency.
>
> Couldn't we just use the `TestSuite` to detect errors?
That is my goal. But we do not agree that returning an `int` for
`.cardinality()` is an error. In many situation, "ensuring" that it is a
Sage integer prevent doing wrong things afterwards.
> When you see a non-integer then something is most probably wrong and the
testsuite should report it. What you are doing right now is simulate a
"return type" for a function in a language that does not support it.
Yes. But having as dependency a ticket "switch from Python to a strongly
typed language" would be too much effort. So Python is a fact and we have
to deal with it.
Let me mention that Python is trying to do some type checking because it
is useful:
{{{
sage: class A(object):
....: def __len__(self):
....: return 'haha! well tried!'
sage: a = A()
sage: len(a)
Traceback (most recent call last):
...
TypeError: an integer is required
}}}
(note that `a.__len__()` returns what you asked it to do).
Vincent
--
Ticket URL: <http://trac.sagemath.org/ticket/18159#comment:23>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.