Skip to content

Missing error for inconsistent TypeVar ordering in base classes #2371

Closed

Description

@migeed-z

Describe the Bug

When a class inherits from two bases that use the same TypeVars in different orders, pyrefly
should report an error. Currently it silently accepts this.

from typing import Generic, TypeVar

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

  class Grandparent(Generic[T1, T2]): ...
  class Parent(Grandparent[T1, T2]): ...
  class BadChild(Parent[T1, T2], Grandparent[T2, T1]): ...  # should error

Unittest already available in the codebase: pyrefly/lib/test/generic_basic.rs — test_inconsistent_type_var_ordering_in_bases

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAOumAE64C2ABAC6nEToDmTEDxuWiyYBxGOhi0IAYwA0TACrsYANVS1q1BQEYmAXkXK1tABSUQO8wEotAJn2Hiq9WYu3rm9NKio4cUbQYmMTq4iwmYhJS0gDaOvIKtgC6VohMhBnU3r7%2BAAqh6OEigVghtGFx2gnJqemZXj5%2BTABCqJgAwgAW0Jgm%2BeWFldVJ8sVBZRWJCdopaRmETEwAxExwnbgArlCYTJL0tCCyIBss0HAk5IggKwCqp1AQbExgG16nuOhwnpgwYM%2BCDFQLAA%2BugNgxsJITPg0pwWFYmABaAB8qxYtEQ1EWi3KLA2tHQz3MADlwZCMUxgPgAL7maiHEBkcpgKCkQgsRhQCgrXKkZms1ZBPD4JjSD6QLj4oEQD6EagrADKMBgTE6LBYxDgiAA9Nqmb9WYRBFxteJtZhcNI4NqxTQIJLAu90Nr-rQmKgAG6oaCobCwUXi%2B1Sp1MXDEJ3nahkFjrdCIj2SOAywkGcwAZkI2ncVHQIGpR1Q0lOCYAYtAYBQ0FhhRc80A

(Only applicable for extension issues) IDE Information

No response

Activity

  1. added this to the V1 Release milestone on Feb 9, 2026
  2. added
    help wantedLarger than "good first issue", but still well-defined and ready for someone to pick up
    on Feb 9, 2026
  3. added theissue type on Feb 9, 2026
  4. oopscompiled commented on Feb 10, 2026

    @oopscompiled
    Contributor

    It seems that we have to make additional checks for ancestor class types when we iterate in MRO to see whether there already exist class type arguments. I can send a PR if you would like.

  5. migeed-z commented on Feb 10, 2026

    @migeed-z
    ContributorAuthor

    @oopscompiled yeah, that approach makes sense to me. I will assign it to you! thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

conformancehelp wantedLarger than "good first issue", but still well-defined and ready for someone to pick uptypechecking

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions