Skip to content

bpo-23819: asyncio: Replace AssertionError with proper excs #29894

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 5 commits into from
Dec 6, 2021

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Dec 2, 2021

@kumaraditya303
Copy link
Contributor Author

cc @gvanrossum This only changes AssertionError with exceptions, this does not removes all asserts as you suggested on bpo

@AlexWaygood
Copy link
Member

Apologies, I should have been clearer in my review. My point wasn't that you should use double-quotes instead of single-quotes — my point was that Python's TypeError messages usually look like this:

policy must be an instance of AbstractEventLoopPolicy or None, not 'str'

Rather than

policy must be an instance of AbstractEventLoopPolicy or None, not str

@kumaraditya303
Copy link
Contributor Author

Apologies, I should have been clearer in my review. My point wasn't that you should use double-quotes instead of single-quotes — my point was that Python's TypeError messages usually look like this:

policy must be an instance of AbstractEventLoopPolicy or None, not 'str'

Rather than

policy must be an instance of AbstractEventLoopPolicy or None, not str

Done

@AlexWaygood
Copy link
Member

Done

Thanks!

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@asvetlov asvetlov changed the title bpo-23819: Replace AssertionError with proper excs bpo-23819: asyncio: Replace AssertionError with proper excs Dec 3, 2021
@kumaraditya303
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@asvetlov: please review the changes made to this pull request.

@asvetlov asvetlov merged commit 265918b into python:main Dec 6, 2021
@asvetlov
Copy link
Contributor

asvetlov commented Dec 6, 2021

Thanks!

@gvanrossum
Copy link
Member

gvanrossum commented Dec 6, 2021 via email

@kumaraditya303 kumaraditya303 deleted the asyncio branch December 11, 2021 08:21
Comment on lines +709 to +710
if delay is None:
raise TypeError('delay must not be None')
Copy link
Member

Choose a reason for hiding this comment

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

It is redundant. A TypeError will be raised at the next line, by self.time() + delay.

Copy link
Contributor

Choose a reason for hiding this comment

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

My thought when I suggested the change was: better to explicitly warn about None argument than a little cryptic unsupported operand type(s) for +: 'NoneType' and 'int'.
I believe not only exception type but also a proper message can help users to avoid silly mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

Why is None special for this argument? I do not know any precedents of checkinjg only for None if other types can be invalid too. It looks like an antipattern to me. We either check for allowed types, or do not check either and let an error be raised later when perform an unsupported operation.

Comment on lines +722 to +723
if when is None:
raise TypeError("when cannot be None")
Copy link
Member

Choose a reason for hiding this comment

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

Why test only for None? What about other invalid types?

Copy link
Contributor

Choose a reason for hiding this comment

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

The same as above: provide descriptive error message for obvious mistakes, raise default errors for all other combinations.

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.

7 participants