Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class My[X](object): raises TypeError: Cannot create a consistent method resolution order #107909

Closed
sobolevn opened this issue Aug 13, 2023 · 3 comments
Assignees
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Aug 13, 2023

>>> class My[X](object): ...
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <generic parameters of My>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Generic

It looks like a correct error:

>>> from typing import Generic
>>> from typing import TypeVar
>>> T = TypeVar('T')
>>> class A(object, Generic[T]): ...
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Generic

>>> class A(Generic[T], object): ...
... 
>>> 

But it is not tested. I think that object is quite an important corner-case to test it explicitly.

class My[X](): is tested.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error topic-typing labels Aug 13, 2023
@sobolevn sobolevn self-assigned this Aug 13, 2023
@brandonardenwalli
Copy link
Contributor

brandonardenwalli commented Aug 15, 2023

Hi! I am to try to follow along, but I am not able to get the same error from the first example you give:

class My[X](object): ...

gives me

File "<stdin>", line 1
    class My[X](object): ...
            ^
SyntaxError: invalid syntax

the second example works for me though:

class A(object, Generic[T]): ...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Generic

Am I doing something wrong? How to fix to reproduce the same error as you?

P.S. how to make code formatting look like your examples? I use the "Add code" button but my code looks different from yours in the preview.
Update for P.S.: see #107909 (comment)

@brandonardenwalli
Copy link
Contributor

brandonardenwalli commented Aug 15, 2023

Okay, I run again after great suggestion from JelleZijlstra in other conversation. I can now reproduce:

>>> class My[X](object): ...
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <generic parameters of My>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Generic
>>> from typing import Generic
>>> from typing import TypeVar
>>> T = TypeVar('T')
>>> class A(object, Generic[T]): ...
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Cannot create a consistent method resolution
order (MRO) for bases object, Generic
>>> class A(Generic[T], object): ...
...

For anyone also stuck with same problem as me above, try to do #107905 (comment)

@AlexWaygood
Copy link
Member

AlexWaygood commented Aug 15, 2023

@brandonardenwalli, please use triple backticks to format multiline code blocks in GitHub issues, i.e.:

```
Your code here 
```

sobolevn added a commit to sobolevn/cpython that referenced this issue Aug 16, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 16, 2023
pythonGH-108001)

(cherry picked from commit b61f599)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Yhg1s pushed a commit that referenced this issue Aug 17, 2023
…es (GH-108001) (#108022)

gh-107909: Test explicit `object` base in PEP695 generic classes (GH-108001)
(cherry picked from commit b61f599)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants