Skip to content

Generic Multiinheritance and MRO ordering #2955

@hmc-cs-mdrissi

Description

@hmc-cs-mdrissi

Describe the bug
Generic is a weird super class. The consistent method ordering rule that applies for other superclasses does not apply for generic at runtime and if a child class wants different number of type variables it may need to directly subclass generic too. The error message,

Cannot create consistent method ordering

should not be triggered from Generic.

To Reproduce

from typing import Generic, TypeVar

T1 = TypeVar("T1")
T2 = TypeVar("T2")


class Foo1(Generic[T1]):
    ...


class Foo2(Generic[T1]):
    ...


class Bar1(Generic[T1], Foo1[T1], Foo2[T1]): # E: Cannot create consistent method ordering
    ...


class Bar2(Generic[T1, T2], Foo1[T1], Foo2[T1]): # E: Cannot create consistent method ordering
    ...

Expected behavior
No errors. Bar1 it doesn't really matter as dropping generic has minimal effect I know of. Bar2 does need Generic though and dropping it would change type information for that class.

VS Code extension or command-line
pyright 1.1.216

Additional context
Python has a sad number of edge case typing rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions