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: TypeError when inheriting from both OSError and AttributeError
Type: behavior Stage: resolved
Components: Documentation, Interpreter Core Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: docs@python Nosy List: christian.heimes, docs@python, lukasz.langa, marmarek, miss-islington, pablogsal, terry.reedy
Priority: normal Keywords: 3.10regression, patch

Created on 2021-10-13 20:05 by marmarek, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28995 closed pablogsal, 2021-10-16 18:00
PR 29094 merged lukasz.langa, 2021-10-20 14:21
PR 29104 merged miss-islington, 2021-10-20 16:54
PR 29105 merged miss-islington, 2021-10-20 16:54
Messages (11)
msg403870 - (view) Author: Marek Marczykowski-Górecki (marmarek) * Date: 2021-10-13 20:05
In Python 3.10 it is no longer possible to create an exception type that inherits from both OSError and AttributeError. This has worked in Python 3.9.
I don't see anything in changelog/release notes that would suggest it being intentional.

Behavior in Python 3.9:

Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class C(OSError, AttributeError): pass
... 
>>> C
<class '__main__.C'>


Behavior in Python 3.10:

Python 3.10.0 (default, Oct  4 2021, 00:00:00) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class C(OSError, AttributeError): pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: multiple bases have instance lay-out conflict


My (very) wild guess is this being related to https://bugs.python.org/issue38530
msg403906 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-10-14 15:26
You are correct. To be more precise, it's caused by GH-16856. The commit introduced PyAttributeErrorObject struct. Since AttributeError and OSError now have an incompatible memory layout, it is no longer possible to create a subclass that has AttributeError and OSError as parent classes.
msg403914 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-10-14 16:23
Unfortunately there isn't much we can do here other than document this :(
msg403918 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-10-14 16:52
Also, just to clarify something: there is no guarantee that multiple build-in, unrelated exceptions can be inherited and this is not supported. And this is not unique to this case. For example:

>>> class A(StopIteration, OSError):
...    ...
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: multiple bases have instance lay-out conflict

>>> class A(SyntaxError, OSError):
...    pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: multiple bases have instance lay-out conflict
>>> class A(ModuleNotFoundError, OSError):
...    ...
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: multiple bases have instance lay-out conflict
msg404075 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-10-16 12:16
Suggestion: At the end of https://docs.python.org/3/bugs.html, add

"Creating a subclass that inherits from multiple exceptions may not work and the potential conflicts may change in new versions."
msg404107 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-10-16 17:57
> Suggestion: At the end of https://docs.python.org/3/bugs.html, add

Hummm, I am not sure that page is the most adecuate for this, no? That is how to deal with bugs in general, not about specific bugs.
msg404469 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-10-20 14:57
More specific would be "Inheriting from multiple exceptions may fail due to instance layout conflicts. Such conflicts may depend on the Python version."  This would effectively say "Don't bother reporting layout conflicts -- we know about them and they are not bugs." while not discouraging reports of other problems.
msg404498 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-10-20 16:54
New changeset dff0b713436e286bb1afdd7c6f3093c8e8db16dd by Łukasz Langa in branch 'main':
bpo-45464: [doc] Explain that subclassing multiple exceptions is fragile (GH-29094)
https://github.com/python/cpython/commit/dff0b713436e286bb1afdd7c6f3093c8e8db16dd
msg404518 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-10-20 18:50
New changeset b2a989995e6b725c5c957927127832fd3fcecfa2 by Miss Islington (bot) in branch '3.10':
bpo-45464: [doc] Explain that subclassing multiple exceptions is fragile (GH-29094) (GH-29104)
https://github.com/python/cpython/commit/b2a989995e6b725c5c957927127832fd3fcecfa2
msg404519 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-10-20 18:50
New changeset 427ab124b3e9a54602b6f1d073a8e073159c0b51 by Miss Islington (bot) in branch '3.9':
bpo-45464: [doc] Explain that subclassing multiple exceptions is fragile (GH-29094) (GH-29105)
https://github.com/python/cpython/commit/427ab124b3e9a54602b6f1d073a8e073159c0b51
msg404520 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-10-20 18:51
Marking this as "wont fix" since only documentation was updated. Thanks for reporting, Marek!
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89627
2021-10-20 18:51:34lukasz.langasetstatus: open -> closed
resolution: wont fix
messages: + msg404520

stage: patch review -> resolved
2021-10-20 18:50:32lukasz.langasetmessages: + msg404519
2021-10-20 18:50:13lukasz.langasetmessages: + msg404518
2021-10-20 16:54:43miss-islingtonsetpull_requests: + pull_request27373
2021-10-20 16:54:39miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request27372
2021-10-20 16:54:36lukasz.langasetmessages: + msg404498
2021-10-20 14:57:34terry.reedysetmessages: + msg404469
2021-10-20 14:21:07lukasz.langasetnosy: + lukasz.langa
pull_requests: + pull_request27364
2021-10-16 18:00:52pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request27279
2021-10-16 17:57:14pablogsalsetmessages: + msg404107
2021-10-16 12:16:41terry.reedysetnosy: + terry.reedy, docs@python
messages: + msg404075

assignee: docs@python
components: + Documentation
2021-10-14 16:52:58pablogsalsetmessages: + msg403918
2021-10-14 16:23:32pablogsalsetmessages: + msg403914
2021-10-14 15:26:20christian.heimessetversions: + Python 3.11
nosy: + christian.heimes

messages: + msg403906

keywords: + 3.10regression
2021-10-14 14:48:09corona10setnosy: + pablogsal
2021-10-13 20:05:16marmarekcreate