This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [io doc] Reword "there is no public constructor"
Type: behavior Stage: resolved
Components: Documentation, IO Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Gerrit.Holl, docs@python, iritkatriel, martin.panter, miss-islington, slateny, terry.reedy
Priority: normal Keywords: easy, patch

Created on 2015-10-15 17:58 by Gerrit.Holl, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
no-args.patch martin.panter, 2015-10-31 11:40 review
Pull Requests
URL Status Linked Edit
PR 31631 merged slateny, 2022-03-01 09:01
PR 31688 merged miss-islington, 2022-03-04 17:36
PR 31689 merged miss-islington, 2022-03-04 17:36
Messages (10)
msg253059 - (view) Author: Gerrit Holl (Gerrit.Holl) * Date: 2015-10-15 17:58
According to the [documentation](https://docs.python.org/3/library/io.html#io.IOBase), `io.IOBase` has no public constructors.  Yet I can create objects from it:

$ python3.5
Python 3.5.0 (default, Sep 13 2015, 17:20:05) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
Python are go!
>>> import io
>>> p = io.IOBase()
>>> p.readable()
False
>>> p.closed
False
# etc...

It doesn't do much, but the documentation is not consistent with the behaviour in practice.
msg253064 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-10-15 22:16
“No public constructor” to me means that it is not defined how or if you can construct instances other than by the public subclasses. What do you expect to happen? How do you expect the public subclasses such as FileIO and BufferedReader to work if the base constructor does not work?

The other three base classes (RawIOBase, BufferedIOBase, TextIOBase) also say “there is no public constructor”. However allowing custom subclasses of these is very useful, so I would actually be for removing these restrictions from the documentation, and instead saying that each constructor accepts no arguments.
msg253065 - (view) Author: Gerrit Holl (Gerrit.Holl) * Date: 2015-10-15 23:05
When the documentation says there is no public constructor, I expected it would be impossible to create instances, as in:

TypeError: cannot create 'builtin_function_or_method' instances

Perhaps I misunderstand the documentation.
msg253117 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-10-17 03:37
Martin, I agree with changing the doc. Gerrit misunderstood because 'no public constructors' is either meaningless or wrong.  We do not usually talk about public versus private constructors.  This sounds more like C++ than Python.

For Python namespaces, names that start with '_' are private by convention unless documented otherwise.  Special names (__x__) are private in the sense that they are not usually used except by methods of the class; special methods are usually accessed by syntax or public names.  For class C, the default constructor is C.__new__, accessed by calling C.  (Let us not worry about other methods here.)  If C is a public name, with no '_', as is 'IOBase', then to me it has/is a public constructor.  Like other classes, IOBase has .__new__ and calling it produces an instance, as Gerrit discovered.  In that sense, it is not truly abstract.

I believe 'has no public constructor' is intended to mean 'has no documented signature and should not be *directly* called."  (If subclasses do call the base, then the signature should be documented.)
msg253783 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-10-31 11:40
If existing subclasses like FileIO call the base, that is an implementation detail. But custom subclasses of the Raw, Buffered, and Text base classes should not be prohibited from chain calling the base’s __init__() method, nor should they have to override __init__() if there is no special initialization to be done. For IOBase itself, I don’t see a strong argument either way, but it makes sense to keep it consistent with the other three base classes.

I propose this patch, which changes “There is no public constructor” to “The constructor accepts no arguments”. In my mind this blesses making custom subclasses, which already seems to be tested and used in practice.
msg407142 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-11-27 12:40
Martin's patch needs to be converted to a GitHub PR and reviewed.
msg414289 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-03-01 19:10
"IOBase" is a public name and IOBase has an __init__ method.  It definitely has a public constructor.  However, like other abstract base classes, it is not meant to be directly instantiated by users other than writers of other classes.  Ditto for the 3 other io ABCs.  Because this is generic to all ABCs, it need not be repeated for each.

The proposed replacement is the opposite of the truth.  Rather than accepting no arguments, IOBase, like the ABCs in numbers and collections.abc, has a generic signature and accepts any arguments (which I believe are ignored).

>>> io.IOBase.__init__.__text_signature__
'($self, /, *args, **kwargs)'
>>> io.IOBase(3, a=5)
<io.IOBase object at 0x000001CF6A13D6C0>

A class, such as `object`, accepting no arguments other that self raises.  (At one time, object had the generic signature above.)

>>> object(3)
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    object(3)
TypeError: object() takes no arguments

I think that the fix should be to delete the original incorrect statement and not replace it with another incorrect statement.

Most abstract base classes are in collections.abc and numbers.  They are not specifically labelled 'abstract base class' in their docstrings because they are in modules consisting more or less entirely of ABCs.  Since io is mostly a module of concrete classes, I think it appropriate to specifically label them, as they are now.  Once so labeled, nothing need be added that is true of all ABCs.
msg414484 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-03 22:33
> I think that the fix should be to delete the original incorrect statement and not replace it with another incorrect statement.


I agree with this.
msg414539 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-03-04 17:36
New changeset cedd2473a9bebe07f3ced4f341cf58a2fef07b03 by slateny in branch 'main':
bpo-25415: Remove confusing sentence from IOBase docstrings (PR-31631)
https://github.com/python/cpython/commit/cedd2473a9bebe07f3ced4f341cf58a2fef07b03
msg414545 - (view) Author: miss-islington (miss-islington) Date: 2022-03-04 18:34
New changeset 01df048831eb631dfee41175f08d09b9ad1a9538 by Miss Islington (bot) in branch '3.9':
bpo-25415: Remove confusing sentence from IOBase docstrings (PR-31631)
https://github.com/python/cpython/commit/01df048831eb631dfee41175f08d09b9ad1a9538
msg414546 - (view) Author: miss-islington (miss-islington) Date: 2022-03-04 18:34
New changeset bdce1880365990403efdbeb60c4928c996370b0c by Miss Islington (bot) in branch '3.10':
bpo-25415: Remove confusing sentence from IOBase docstrings (PR-31631)
https://github.com/python/cpython/commit/bdce1880365990403efdbeb60c4928c996370b0c
History
Date User Action Args
2022-04-11 14:58:22adminsetgithub: 69601
2022-03-04 18:38:01terry.reedysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-03-04 18:34:18miss-islingtonsetmessages: + msg414546
2022-03-04 18:34:18miss-islingtonsetmessages: + msg414545
2022-03-04 17:36:24miss-islingtonsetpull_requests: + pull_request29808
2022-03-04 17:36:19miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request29807
2022-03-04 17:36:04terry.reedysetmessages: + msg414539
2022-03-03 22:33:53iritkatrielsetmessages: + msg414484
2022-03-01 19:10:26terry.reedysetmessages: + msg414289
title: [doc] "there is no public constructor" should be reworded in io module documentation -> [io doc] Reword "there is no public constructor"
2022-03-01 09:01:37slatenysetkeywords: + patch
nosy: + slateny
pull_requests: + pull_request29753
2021-11-27 12:40:09iritkatrielsettype: behavior
title: I can create instances of io.IOBase -> [doc] "there is no public constructor" should be reworded in io module documentation

keywords: + easy, - patch
nosy: + iritkatriel
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.4, Python 3.5, Python 3.6
messages: + msg407142
2015-10-31 11:40:02martin.pantersetfiles: + no-args.patch
versions: + Python 2.7, Python 3.4, Python 3.6
messages: + msg253783

keywords: + patch
stage: patch review
2015-10-17 03:37:21terry.reedysetnosy: + terry.reedy
messages: + msg253117
2015-10-15 23:05:33Gerrit.Hollsetmessages: + msg253065
2015-10-15 22:16:41martin.pantersetnosy: + docs@python, martin.panter
messages: + msg253064

assignee: docs@python
components: + Documentation, IO, - Library (Lib)
2015-10-15 17:58:54Gerrit.Hollcreate