Skip to content

gh-98284: better error message for undefined abstractmethod - #97971

Merged
JelleZijlstra merged 5 commits into
python:mainfrom
kaushikcfd:abc_better_err_msg
Nov 5, 2022
Merged

gh-98284: better error message for undefined abstractmethod#97971
JelleZijlstra merged 5 commits into
python:mainfrom
kaushikcfd:abc_better_err_msg

Conversation

@kaushikcfd

@kaushikcfdkaushikcfd commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

Error message before:

TypeError: Can't instantiate abstract class IndexNode with abstract method name

Error message after this patch:

TypeError: Can't instantiate abstract class IndexNode with abstract method 'name'

Given that the style-guide requires method names to be in lowercase, the quotation marks help in differentiating the sentence from the method's name.

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost

ghost commented Oct 6, 2022

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

Comment threadLib/test/test_abc.py Outdated
def method_two(self):
pass
msg = r"class C without an implementation for abstract methods method_one, method_two"
msg = r"class C without an implementation for abstract methods 'method_one, method_two'"

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 is incorrect, we should quote each method individually.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks, done!

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@kaushikcfd
kaushikcfd requested review from JelleZijlstra and removed request for ericvsmith and markshannonOctober 9, 2022 16:10
@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@JelleZijlstra

Copy link
Copy Markdown
Member

You do need a NEWS entry as the good knight Bedevere keeps telling you.

Also, avoid force-pushing; it makes review harder. We'll squash-merge anywhere when we merge a PR.

@kaushikcfd

Copy link
Copy Markdown
ContributorAuthor

You do need a NEWS entry as the good knight Bedevere keeps telling you.

Done!

Also, avoid force-pushing;

Noted, thanks!

@@ -0,0 +1,3 @@
Improved :class:`TypeError` message for undefined abstract methods of a

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.

The NEWS entry must refer to an issue, not a PR. You'll have to create an issue and rename the file to have your issue number in the file name.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks, see 4073b1f.

@kaushikcfdkaushikcfd changed the title [abc] better error message for undefined abstractmethodgh-98284: better error message for undefined abstractmethodOct 15, 2022
@kaushikcfd

Copy link
Copy Markdown
ContributorAuthor

The CI failure is (most likely) unrelated:

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'D:\\a\\cpython\\cpython\\build\\test_python_2628�\\test_python_worker_1152�'

@sobolevnsobolevn reopened this Oct 15, 2022
@sobolevn

Copy link
Copy Markdown
Member

Retriggering CI, it is indeed unrelated.

@kaushikcfd

Copy link
Copy Markdown
ContributorAuthor

Retriggering CI, it is indeed unrelated.

Thanks, yep that was it.

@kaushikcfd

Copy link
Copy Markdown
ContributorAuthor

Soft ping.

Comment threadObjects/typeobject.c
method_count > 1 ? "s" : "",
joined);
Py_DECREF(joined);
Py_DECREF(comma_w_quotes_sep);

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.

You also need to DECREF this in the two return NULL branches above.

Come to think of it, the second of those already leaks joined. It needs a Py_DECREF(joined).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Aah, yep! Fixed in 6ae052e.

Sign up for freeto 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.

4 participants

@kaushikcfd@bedevere-bot@JelleZijlstra@sobolevn