[quote=“steven.daprano, post:2, topic:2037”]
Does denominator need to be a method in SageMath? Why couldn’t they have
used a property?
[/quote]
That doesn’t really matter. Maybe SageMath could have used a property,
but they didn’t. It’s just a choice, there is nothing wrong with a
method.
It matters in case SageMath need to pass arguments to the denominator()
method. That would seriously limit their ability to change to a
property.
It matters because SageMath, or rather you on behalf of SageMath, are
asking us to change an API for the entire Python ecosystem, likely
breaking masses of code, so that they can meet the Rational ABC without
changing their APIs. Why should we ask everyone else to change their
code to save SageMath a bit of effort?
[quote=“steven.daprano, post:2, topic:2037”]
they should just deprecate the current behaviour and use a property.
[/quote]
I don’t see how to do that technically. What kind of object would q.denominator
then be?
I don’t understand your question. If I take it literally, it implies
that you don’t know what properties are, and surely that’s not the case.
q.denominator
would be a property object, which is a kind of
descriptor, that returns whatever kind of object SageMath wants to
return. Probably an int for numbers, possibly a polynomial object if
they support polynomial division, possibly other things.
Assuming that SageMath wants to support the Rational ABC, that means
they would go through a deprecation period where q.denominator() raises
a warning. At the end of the deprecation period, change the method to a
property.
Surely I don’t need to explain to you how to change a method into a
property? I can’t help but feel we must be talking past each other.
def denominator(self):
warnings.warn("denominator will stop being a method in version X")
# implementation goes here
becomes
@property
def denominator(self):
# implementation goes here
If they want to avoid a hard cut-off from one behaviour to the other,
they could return a value with a call method that returns self. That
way, q.denominator() and q.denominator will both return the same object.