Skip to content

Add error when making abstractmethod final - #12743

Merged
JelleZijlstra merged 2 commits into
python:masterfrom
nakatomotoi:issue-12164
May 8, 2022
Merged

JelleZijlstra merged 2 commits into
python:masterfrom
nakatomotoi:issue-12164

Conversation

@nakatomotoi

Copy link
Copy Markdown
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.

Comment thread mypy/semanal.py Outdated
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
Copy Markdown
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
Copy Markdown
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

github-actions Bot commented May 8, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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