mypy icon indicating copy to clipboard operation
mypy copied to clipboard

[mypyc] Raise "non-trait base must be first..." error less frequently

Open ichard26 opened this issue 3 years ago • 2 comments

It would raise even if there were only non-trait bases, leading to this slightly confusing situation:

class A: pass
class B: pass
class C(A, B): pass  # E: Non-trait bases must appear first in parent list
                     # E: Multiple inheritance is not supported (except for traits)

Now the bases must include a non-trait and the first base must be a trait to error. This leads to some false-negatives when there's more than one non-trait base, but in that case, it's better to only tell the user that multiple inheritance is not supported.

See also: https://github.com/mypyc/mypyc/issues/826#issuecomment-1383215915

ichard26 avatar Jan 18 '23 00:01 ichard26

This is a draft now because I'd like to also add a check for traits subclassing concrete classes (raising an error if so). It's almost ready to be pushed, but I need to finish the commandline tests and write a good commit message.

ichard26 avatar Jan 19 '23 02:01 ichard26

Turns out that traits are allowed to subclass concrete classes as long as the MRO is linear (ie. no multiple inheritance just like for regular native classes).

ichard26 avatar Jan 21 '23 17:01 ichard26