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

Use public classes for contextlib.suppress and redirect_stdout #63529

Closed
ncoghlan opened this issue Oct 21, 2013 · 7 comments
Closed

Use public classes for contextlib.suppress and redirect_stdout #63529

ncoghlan opened this issue Oct 21, 2013 · 7 comments
Assignees
Labels
release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ncoghlan
Copy link
Contributor

BPO 19330
Nosy @ncoghlan, @larryhastings, @ethanfurman, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/ncoghlan'
closed_at = <Date 2013-10-26.08:08:28.990>
created_at = <Date 2013-10-21.14:00:52.200>
labels = ['type-bug', 'library', 'release-blocker']
title = 'Use public classes for contextlib.suppress and redirect_stdout'
updated_at = <Date 2013-10-26.12:21:32.163>
user = 'https://github.com/ncoghlan'

bugs.python.org fields:

activity = <Date 2013-10-26.12:21:32.163>
actor = 'python-dev'
assignee = 'ncoghlan'
closed = True
closed_date = <Date 2013-10-26.08:08:28.990>
closer = 'python-dev'
components = ['Library (Lib)']
creation = <Date 2013-10-21.14:00:52.200>
creator = 'ncoghlan'
dependencies = []
files = []
hgrepos = []
issue_num = 19330
keywords = []
message_count = 7.0
messages = ['200782', '201319', '201323', '201325', '201331', '201338', '201339']
nosy_count = 5.0
nosy_names = ['ncoghlan', 'larry', 'ethan.furman', 'python-dev', 'serhiy.storchaka']
pr_nums = []
priority = 'release blocker'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue19330'
versions = ['Python 3.4']

@ncoghlan
Copy link
Contributor Author

I broke help() for instances of these context managers by trying to postpone exposing the class APIs until 3.5 (and didn't even record my full rationale, however flawed, in the associated comments).

The wrapper functions should be removed, making the classes the public implementation. I also plan to make the following changes (although I may end up moving them to separate issues):

  • provide (and document) a public "target" attribute on redirect_stdout

  • make redirect_stdout reentrant (and switch to ExitStack as the reusable-but-not-reentrant example)

  • provide (and document) a public "exceptions" attribute on suppress

  • return self from suppress.__enter__

@ncoghlan ncoghlan self-assigned this Oct 21, 2013
@ncoghlan ncoghlan added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 21, 2013
@ncoghlan
Copy link
Contributor Author

I decided to defer adding any public attributes to these APIs - that greatly simplifies this patch, is more consistent with the draft wording in the PEP-8 update (bpo-19331), and if the demand for improved introspection support is there, we can always add them for 3.5.

@ncoghlan
Copy link
Contributor Author

I checked the other classes in contextlib to ensure they also provided decent docstrings on instances. They were mostly OK, but @contextmanager itself doesn't provide useful docs when inspecting the result context manager instances directly. However, fixing that isn't trivial: see bpo-19404 for details.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Oct 26, 2013

New changeset 09153a9a3bb9 by Nick Coghlan in branch 'default':
Close bpo-19330 by using public classes in contextlib
http://hg.python.org/cpython/rev/09153a9a3bb9

@python-dev python-dev mannequin closed this as completed Oct 26, 2013
@serhiy-storchaka
Copy link
Member

I suppose tests will fail when Python is compiled with --without-doc-strings options. Perhaps the test.support.requires_docstrings decorator should be used.

@ncoghlan
Copy link
Contributor Author

It also fails under -OO, so I changed that decorator to deal with that case as well.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Oct 26, 2013

New changeset a9bbc2d0c1dc by Nick Coghlan in branch 'default':
Issue bpo-19330: Handle the no-docstrings case in tests
http://hg.python.org/cpython/rev/a9bbc2d0c1dc

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants