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

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

Merged

Conversation

ichard26
Copy link
Collaborator

@ichard26 ichard26 commented Jan 18, 2023

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: mypyc/mypyc#826 (comment)

@ichard26 ichard26 force-pushed the better-trait-n-multi-inheritance-errors branch 3 times, most recently from 82cb33d to 6d47ef9 Compare January 18, 2023 00:33
@ichard26 ichard26 marked this pull request as draft January 18, 2023 14:17
@ichard26
Copy link
Collaborator Author

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.

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-negative when there's more
than one non-trait base, but in that case, it's better to only tell the
user multiple inheritance is not supported.
@ichard26 ichard26 force-pushed the better-trait-n-multi-inheritance-errors branch from 6d47ef9 to 405c272 Compare January 21, 2023 17:13
@ichard26 ichard26 marked this pull request as ready for review January 21, 2023 17:14
@ichard26
Copy link
Collaborator Author

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).

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@JukkaL JukkaL merged commit 27f51fc into python:master Feb 5, 2023
@ichard26 ichard26 deleted the better-trait-n-multi-inheritance-errors branch May 8, 2023 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants