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

Do not block on duplicate base classes #15367

Merged
merged 4 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ def verify_base_classes(self, defn: ClassDef) -> bool:
cycle = True
dup = find_duplicate(info.direct_base_classes())
if dup:
self.fail(f'Duplicate base class "{dup.name}"', defn, blocker=True)
self.fail(f'Duplicate base class "{dup.name}"', defn)
return False
return not cycle

Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -4131,6 +4131,18 @@ class C(str, str):
[out]
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
main:1: error: Duplicate base class "str"

[case testDupBaseClassesIsNotBlocking]
class A:
def method(self) -> str: ...

class B(A, A): # E: Duplicate base class "A"
...

b: B
# We use dummy type info, so no real attrs will be there:
Copy link
Member

Choose a reason for hiding this comment

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

That's pretty unfortunate, can we make it inherit from Any or just skip the duplicate base instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeap, got it. Fixed!

b.method() # E: "B" has no attribute "method"
[out]

[case testCannotDetermineMro]
class A: pass
class B(A): pass
Expand Down