You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is true for Complex, Real, Rational, Integral but not for Number:
>>> numbers.Number()
<numbers.Number object at 0x7fcccc71f3c0>
>>> numbers.Real()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class Real...
Since Number doesn't have any abstract methods, the correct fix seems to be changing the documentation. I would try to convey something like this:
"The types defined in this module can be used for subclassing and checking whether a specific class is in the numeric hierarchy; they are not used directly for instantiation. For this, you can use types such as complex or fractions.Fraction".
Maybe some methods from the Complex class could be moved to the Number class?
I think, that something like the ring structure (probably even a commutative ring) is expected from the number classes in the Python. I.e. there should be __add__/sub/mul/pos/neg/pow/etc. But not __truediv__/floordiv.
Even simpler idea: move the __eq__ method to the Number class.
Then it would be impossible to instantiate a Number.
Activity
abcdef commentedon Nov 25, 2017
Documentation of the numbers module:
https://docs.python.org/3/library/numbers.html
states "None of the types defined in this module can be instantiated."
This is true for Complex, Real, Rational, Integral but not for Number:
Since Number doesn't have any abstract methods, the correct fix seems to be changing the documentation. I would try to convey something like this:
"The types defined in this module can be used for subclassing and checking whether a specific class is in the numeric hierarchy; they are not used directly for instantiation. For this, you can use types such as
complexorfractions.Fraction".miguendes commentedon May 14, 2021
Seen that nobody is working on this I transformed the suggestion into a PR.
adityasriramb commentedon May 14, 2021
I would like work on this, but I'm very new to fixing bugs. Could someone please help me on how to proceed with this bug. Thank You in advance
rhettinger commentedon May 14, 2021
Here's a minimal change:
+ None of the types defined in this module are intended to be instantiated.
miguendes commentedon May 15, 2021
@rhettinger added your suggestion.
skirpichev commentedon May 15, 2021
Maybe some methods from the Complex class could be moved to the Number class?
I think, that something like the ring structure (probably even a commutative ring) is expected from the number classes in the Python. I.e. there should be __add__/sub/mul/pos/neg/pow/etc. But not __truediv__/floordiv.
Even simpler idea: move the __eq__ method to the Number class.
Then it would be impossible to instantiate a Number.
rhettinger commentedon May 15, 2021
New changeset 3767401 by Miss Islington (bot) in branch '3.9':
bpo-32133: Improve numbers docs (GH-26124) (GH-26147)
3767401
rhettinger commentedon May 15, 2021
New changeset a38db84 by Miss Islington (bot) in branch '3.10':
bpo-32133: Improve numbers docs (GH-26124) (GH-26149)
a38db84