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

gh-114091: Reword error message for unawaitable types #114090

Merged

Conversation

swfarnsworth
Copy link
Contributor

@swfarnsworth swfarnsworth commented Jan 15, 2024

Currently, attempting to await something that cannot be awaited results in this error message:

import asyncio

async def main():
    await 1

asyncio.run(main())

# TypeError: object int can't be used in 'await' expression

I recently encountered this for the first time when the unawaitable object was a method (which was not being called), and found the phrase "object method" unclear. This PR changes the error message so that the name of the class precedes the word "object" and appears in single quotes. A similar construction appears elsewhere in the code base.

>>> 1[2]
TypeError: 'int' object is not subscriptable

 
Thank you to @JelleZijlstra and @godlygeek for their input to this PR (though they do not necessarily endorse it).

"object $type can't be ..." -> "'$type' object can't be ..."
Copy link

cpython-cla-bot bot commented Jan 15, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 15, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@JelleZijlstra
Copy link
Member

This will need a NEWS entry since it's a user-visible change. That means you'll also need to create an issue, then rename this PR with the issue number (e.g., "gh-110491: Reword error message...) and use that issue number in the NEWS entry (step 8 in https://devguide.python.org/#quick-reference).

As for the contents, I like the change. What do you think though of instead changing the text of "'int' object is not awaitable'? That is even shorter, seems just as clear, and matches other errors like the subscript one.

@swfarnsworth
Copy link
Contributor Author

swfarnsworth commented Jan 15, 2024

What do you think though of instead changing the text of "'int' object is not awaitable"?

I agree and will implement this change.

@swfarnsworth swfarnsworth changed the title Reword error message for unawaitable types gh-114091: Reword error message for unawaitable types Jan 15, 2024
@gvanrossum
Copy link
Member

This doesn't look like something that would require an issue (though it does need a news blurb). IIRC it's possible to have a news entry without an issue? (You can try using the PR number as issue number in the blurb form.)

@JelleZijlstra
Copy link
Member

IIRC it's possible to have a news entry without an issue?

I don't think so.

"can't be used in 'await' expression" -> "can't be awaited"
@bedevere-app
Copy link

bedevere-app bot commented Jan 15, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@kumaraditya303 kumaraditya303 merged commit 2c7209a into python:main Jun 17, 2024
38 checks passed
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
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.

5 participants