Skip to content

gh-111085 Fix logic order causing nicer error to never be raised in asyncio.Timeout #110910

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

Closed
wants to merge 4 commits into from

Conversation

Gobot1234
Copy link
Contributor

@Gobot1234 Gobot1234 commented Oct 15, 2023

I don't think this needs a news entry or an issue

@Gobot1234 Gobot1234 changed the title Fix logic order causing nicer error to never be raised Fix logic order causing nicer error to never be raised in asyncio.Timeout Oct 15, 2023
Copy link
Contributor

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this! However, it does need a NEWS entry since exception type change is user visible behaviour

@Gobot1234
Copy link
Contributor Author

@hauntsaninja does this also need an issue then?

@AlexWaygood
Copy link
Member

AlexWaygood commented Oct 19, 2023

@hauntsaninja does this also need an issue then?

Yeah, it's not possible to add a news entry without linking the news entry to a GitHub issue.

(Or, shouldn't be possible, anyway, since the news entry is meant to be linked to an issue :p )

@Gobot1234 Gobot1234 changed the title Fix logic order causing nicer error to never be raised in asyncio.Timeout gh-111085 Fix logic order causing nicer error to never be raised in asyncio.Timeout Oct 19, 2023
Copy link
Member

@Eclips4 Eclips4 left a comment

Choose a reason for hiding this comment

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

LGTM. Should it be backported to 3.12?

@Gobot1234
Copy link
Contributor Author

Turns out the bug exists on 3.11 as well

@Eclips4 Eclips4 added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Oct 19, 2023
@serhiy-storchaka serhiy-storchaka self-requested a review October 19, 2023 22:28
@hauntsaninja
Copy link
Contributor

hauntsaninja commented Oct 20, 2023

I think this probably should not be backported. This effectively just changes a bad error message to a good one and has a chance of breaking code, so doesn't feel like good cost benefit.

Thanks again, I see Serhiy self requested review, so will wait for that before merging.

@hauntsaninja hauntsaninja removed needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Oct 20, 2023
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Oct 20, 2023
asyncio.TaskGroup and asyncio.Timeout classes now raise proper RuntimeError
if they are improperly used.

* When they are used without entering the context manager.
* When they are used after finishing.
* When the context manager is entered more than once (simultaneously or
  sequentially).
* If there is no current task when entering the context manager.

They are now left in consistent state after raising an exception, so
following operations can be correctly performed (if they are allowed).
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Oct 20, 2023
asyncio.TaskGroup and asyncio.Timeout classes now raise proper RuntimeError
if they are improperly used.

* When they are used without entering the context manager.
* When they are used after finishing.
* When the context manager is entered more than once (simultaneously or
  sequentially).
* If there is no current task when entering the context manager.

They are now left in consistent state after raising an exception, so
following operations can be correctly performed (if they are allowed).

Co-authored-by: James Hilton-Balfe <[email protected]>
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Oct 20, 2023
asyncio.TaskGroup and asyncio.Timeout classes now raise proper RuntimeError
if they are improperly used.

* When they are used without entering the context manager.
* When they are used after finishing.
* When the context manager is entered more than once (simultaneously or
  sequentially).
* If there is no current task when entering the context manager.

They are now left in consistent state after raising an exception, so
following operations can be correctly performed (if they are allowed).

Co-authored-by: James Hilton-Balfe <[email protected]>
@Gobot1234
Copy link
Contributor Author

Closing in favour of #111111

@Gobot1234 Gobot1234 closed this Oct 20, 2023
@serhiy-storchaka
Copy link
Member

While this change fixes an AttributeError in __enter__(), it left the object in inconsistent state, so other AttributeError can be raised in specific circumferences in other place. There are also other issues in the current code. It makes sense to fix them all at once.

In any case, thank you for your contribution. I included your changes in the other PR and added you as a co-author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants