Skip to content

bpo-41543: contextlib.nullcontext can fill in for an async context manager#21870

Merged
asvetlov merged 2 commits into
python:masterfrom
tomgrin10:async-nullcontext
Nov 9, 2020
Merged

bpo-41543: contextlib.nullcontext can fill in for an async context manager#21870
asvetlov merged 2 commits into
python:masterfrom
tomgrin10:async-nullcontext

Conversation

@tomgrin10

@tomgrin10 tomgrin10 commented Aug 13, 2020

Copy link
Copy Markdown
Contributor

Make contextlib.nullcontext implement AbstractAsyncContextManager, so it can be used as a fill in for async context mangers.

https://bugs.python.org/issue41543

@tomgrin10
tomgrin10 requested a review from 1st1 as a code owner August 13, 2020 21:19
@tomgrin10 tomgrin10 changed the title bpo-41543: contextlib.nullcontext can fill in an async context manager bpo-41543: contextlib.nullcontext can fill in for an async context manager Aug 13, 2020

@iritkatriel iritkatriel left a comment

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.

Missing a test

@1st1

1st1 commented Aug 14, 2020

Copy link
Copy Markdown
Member

Yes, please add a test and update the docs.

@iritkatriel

Copy link
Copy Markdown
Member

It might be tidier to have a separate NullAsyncContext.

@tomgrin10

Copy link
Copy Markdown
Contributor Author

It might be tidier to have a separate NullAsyncContext.

Because nullcontext is used as a fill in for other objects, I think it would be confusing to have two versions of it.

@tomgrin10

Copy link
Copy Markdown
Contributor Author

Added test and updated docs :)

@iritkatriel iritkatriel left a comment

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.

Still need to squash the commits.

Comment thread Doc/library/contextlib.rst Outdated
@tomgrin10

Copy link
Copy Markdown
Contributor Author

I fixed the example and squashed the commits

@iritkatriel

Copy link
Copy Markdown
Member

Looks like there are still 4 commits. It will be easier for people looking at this change in the future if the code change, test, and documentation change are all in a single commit.

@tomgrin10

Copy link
Copy Markdown
Contributor Author

My bad, thought that if the commits get merge --squashed, they shouldn't all be in one commit, now they're actually squashed 😅

@ZackerySpytz

Copy link
Copy Markdown
Contributor

For what it's worth, the developer's guide states that squashing should be avoided.

Comment thread Doc/library/contextlib.rst Outdated
@tomgrin10

Copy link
Copy Markdown
Contributor Author

Is this gonna get merged?

@tomgrin10 tomgrin10 closed this Aug 20, 2020
@tomgrin10 tomgrin10 reopened this Aug 20, 2020
@iritkatriel

Copy link
Copy Markdown
Member

@ZackerySpytz, I see what you mean now - the core devs squash commits on merge so it doesn't matter if the PR is messy. Thanks for pointing this out.

@1st1

1st1 commented Sep 2, 2020

Copy link
Copy Markdown
Member

Yes, this is ready for merge. Just trying to get the CI pass.

@tomgrin10 tomgrin10 closed this Sep 5, 2020
@tomgrin10 tomgrin10 reopened this Sep 5, 2020
@iritkatriel

Copy link
Copy Markdown
Member

I guess this can be merged now.

@tomgrin10 tomgrin10 closed this Oct 5, 2020
@tomgrin10 tomgrin10 reopened this Oct 5, 2020
@tomgrin10

Copy link
Copy Markdown
Contributor Author

Is this gonna get merged someday? Is there a way to fix the broken CI?

@tomgrin10 tomgrin10 closed this Oct 26, 2020
@tomgrin10 tomgrin10 reopened this Oct 26, 2020
@tomgrin10
tomgrin10 requested a review from 1st1 October 26, 2020 19:54

@asvetlov asvetlov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

As the aiohttp author, I never use such approach :)

@asvetlov asvetlov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need ..versionchanged:: 3.10 directive in docs that says 'added support for async context manager' or something like this

@bedevere-bot

Copy link
Copy Markdown

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.

@tomgrin10

tomgrin10 commented Nov 4, 2020

Copy link
Copy Markdown
Contributor Author

Need ..versionchanged:: 3.10 directive in docs that says 'added support for async context manager' or something like this

@asvetlov Do you feel it's better to add the directive before my example, or that an another example for nullcontext is redundant and just the directive is enough?

…nager

Add NEWS.d blurb


Add tests


Fix test


Update nullcontext docs


Fix example in docs


Format lines
@asvetlov

asvetlov commented Nov 4, 2020

Copy link
Copy Markdown
Contributor

I expect to see ..versionchanged:: 3.10 at the next line to ..versionadded:: 3.7 (plus an empty line as a separator).

@tomgrin10

Copy link
Copy Markdown
Contributor Author

I expect to see ..versionchanged:: 3.10 at the next line to ..versionadded:: 3.7 (plus an empty line as a separator).

I got that, but I question whether to remove my example entirely and leave only the directive.
What do you think?

Comment thread Doc/library/contextlib.rst
@asvetlov

asvetlov commented Nov 9, 2020

Copy link
Copy Markdown
Contributor

I think the example is fine, but versionadded should mention the change.

Updated docs.

@asvetlov

asvetlov commented Nov 9, 2020

Copy link
Copy Markdown
Contributor

Thanks for the patience!

adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…nager (pythonGH-21870)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
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