Somewhat similar in spirit, I think that functions should try to return objects of the same type, unless explicitly called with an argument to change such behavior.

It is not just the case of int and Integer. This might happen with Integer vs. Rational, where a function that usually use division, might in certain conditions returns an Integer (or more generally, an element of an integral domain rather than an element of the fraction field).
Of course there is nuance. For example, the 'binomial' function coerce its arguments, or using nullable types when there is a certificate argument, and so on.

Regards,
TB

On 12/07/2021 16:50, David Roe wrote:
I think it's fine to include a discussion of this in the developer's manual: functions should return an integer rather than an int unless there is a good reason not to (mandated by the language for __len__, to reduce overhead for some internal functions).
David

On Mon, Jul 12, 2021 at 3:26 AM Kwankyu Lee <ekwan...@gmail.com> wrote:


On Monday, July 12, 2021 at 12:44:05 AM UTC+9 Nils Bruin wrote:
I'd expect it's (1). A more nuanced version might be:

(5) As a rule, an Integer should probably be returned if the code is probably going to interact with other sage code, but if you have good (efficiency) reasons to prefer a python integer or if the primary function is to be compatible with other python code (such as "len" methods) then returning a python integer should be fine.

This sounds close to (2) as most of Sage library code is for mathematics. 

Do you or anyone object to include a hint of this policy in the developer manual? 
--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/553f7cad-3dcc-4a8c-a3c8-916e7b5706d8n%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/CAChs6_%3Dm38VsmkqAqv9dMB2%3DSyb%2BfmNPZANrsAcwmG6JacXGww%40mail.gmail.com.


--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/8caed312-d661-4836-ef96-d3b3bcc419db%40gmail.com.

Reply via email to