classification
Title: documentation: numbers module nitpick
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Sergey.Kirpichev, abcdef, adityasriram.b, docs@python, miguendes, miss-islington, rhettinger
Priority: normal Keywords: easy, patch

Created on 2017-11-25 18:31 by abcdef, last changed 2021-05-15 17:29 by rhettinger. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 26124 merged miguendes, 2021-05-15 08:11
PR 26147 merged miss-islington, 2021-05-15 16:56
PR 26149 merged miss-islington, 2021-05-15 17:02
Messages (8)
msg306970 - (view) Author: (abcdef) Date: 2017-11-25 18:31
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:

>>> 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`".
msg393636 - (view) Author: Miguel Brito (miguendes) * Date: 2021-05-14 09:42
Seen that nobody is working on this I transformed the suggestion into a PR.
msg393673 - (view) Author: Bhaskara Aditya Sriram (adityasriram.b) Date: 2021-05-14 16:15
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
msg393679 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-05-14 17:08
Here's a minimal change:

- None of the types defined in this module can be instantiated.
+ None of the types defined in this module are intended to be instantiated.
msg393705 - (view) Author: Miguel Brito (miguendes) * Date: 2021-05-15 08:14
@rhettinger added your suggestion.
msg393706 - (view) Author: Sergey B Kirpichev (Sergey.Kirpichev) * Date: 2021-05-15 08:22
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.
msg393720 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-05-15 17:28
New changeset 376740110ecb2440fee9e04f325131aaefeb5c47 by Miss Islington (bot) in branch '3.9':
bpo-32133: Improve numbers docs (GH-26124) (GH-26147)
https://github.com/python/cpython/commit/376740110ecb2440fee9e04f325131aaefeb5c47
msg393721 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-05-15 17:28
New changeset a38db84122b4f664ee30b9ffd55ce87b7f4517ac by Miss Islington (bot) in branch '3.10':
bpo-32133: Improve numbers docs (GH-26124) (GH-26149)
https://github.com/python/cpython/commit/a38db84122b4f664ee30b9ffd55ce87b7f4517ac
History
Date User Action Args
2021-05-15 17:29:29rhettingersetstatus: open -> closed
assignee: docs@python -> rhettinger
resolution: fixed
stage: patch review -> resolved
2021-05-15 17:28:58rhettingersetmessages: + msg393721
2021-05-15 17:28:14rhettingersetmessages: + msg393720
2021-05-15 17:02:04miss-islingtonsetpull_requests: + pull_request24785
2021-05-15 16:56:23miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request24783
2021-05-15 08:22:40Sergey.Kirpichevsetmessages: + msg393706
2021-05-15 08:14:28miguendessetmessages: + msg393705
2021-05-15 08:11:13miguendessetkeywords: + patch
stage: patch review
pull_requests: + pull_request24775
2021-05-14 17:08:09rhettingersetnosy: + rhettinger
messages: + msg393679
2021-05-14 16:15:19adityasriram.bsetnosy: + adityasriram.b
messages: + msg393673
2021-05-14 09:42:03miguendessetnosy: + miguendes
messages: + msg393636
2021-05-09 11:36:29iritkatrielsetkeywords: + easy
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.6
2021-04-23 08:41:09Sergey.Kirpichevsetnosy: + Sergey.Kirpichev
2017-11-25 18:31:43abcdefcreate