Title: Cryptic error message when creating types that don't include themselves in their MRO
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.9, Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ppperry, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-02-17 17:00 by ppperry, last changed 2020-03-26 00:03 by ppperry.

Messages (2)
msg362152 - (view) Author: (ppperry) Date: 2020-02-17 17:00
I was trying to create a class that didn't have any references to itself to test issue39382 and ran the following code:

class Meta(type):
	def mro(cls):
		return type.mro(cls)[1:]
class X(metaclass=Meta):

This produced an extremely cryptic error message:

Traceback (most recent call last):
  File "<pyshell#89>", line 1, in <module>
    class X(metaclass=Meta):
TypeError: super(type, obj): obj must be an instance or subtype of type

While what I am trying to do may well not be supported, the error message referencing the `super` function, which I didn't use, is not helpful.
msg362154 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-02-17 18:26
Yes, I got the same error message when tried to get such class.

super() is called implicitly by the type constructor to call __init_subclass__ on the parent of a newly generated type.
Date User Action Args
2020-03-26 00:03:35ppperrysetcomponents: - Build
versions: + Python 3.9
2020-02-17 18:26:45serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg362154
2020-02-17 17:00:26ppperrycreate