Skip to content

Add error when making abstractmethod final #12743

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

Merged
merged 2 commits into from
May 8, 2022

Conversation

nakatomotoi
Copy link
Contributor

Description

This fixes #12164.
When an abstract method is tried to make as final, an error will be raised.

Test Plan

Added a simple test case to make sure mypy doesn't raise an exception.

@github-actions

This comment has been minimized.

mypy/semanal.py Outdated
@@ -1103,6 +1103,8 @@ def visit_decorator(self, dec: Decorator) -> None:
dec.func.accept(self)
if dec.decorators and dec.var.is_property:
self.fail('Decorated property not supported', dec)
if dec.func.is_abstract and dec.func.is_final:
self.fail(f"Final method {dec.func.name} has abstract attributes", dec)
Copy link
Member

Choose a reason for hiding this comment

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

This error message doesn't work very well here. Suggested change:

Suggested change
self.fail(f"Final method {dec.func.name} has abstract attributes", dec)
self.fail(f"Method {dec.func.name} is both abstract and final", dec)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JelleZijlstra
Thank you for your review!
I'll change the error message!

@nakatomotoi nakatomotoi requested a review from JelleZijlstra May 8, 2022 03:52
@JelleZijlstra JelleZijlstra self-assigned this May 8, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 8, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit f28bf11 into python:master May 8, 2022
@AlexWaygood
Copy link
Member

Congrats on your first contribution, @nakatomotoi!

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.

no error when making abstractmethod final
3 participants