This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2013年10月26日 07:22 by ncoghlan, last changed 2022年04月11日 14:57 by admin.
| Messages (5) | |||
|---|---|---|---|
| msg201322 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2013年10月26日 07:22 | |
While working on issue 19330, I also took a look at whether or not I could fix the @contextmanager decorator to also provide useful help information on the resulting objects. This turned out to be difficult, since calling decorated functions produces instances of contextlib._GeneratorContextManager, and help() insists on showing the docs for that rather than a __doc__ attribute set on the context manager instance itself. This behaviour appears to be ultimately due to "pydoc.render_doc()", which has a hardcoded list of conditions it checks to decide whether to document the instance directly or to provide the class documentation instead: http://hg.python.org/cpython/file/2b904290b3b9/Lib/pydoc.py#l1544 This first idea that comes to mind is to simply add the additional condition that if "obj.__doc__ != type(obj).__doc__", then help() shouldn't replace the object with it's type. The simple trick that I originally explored was simply setting the __doc__ attribute on the _GeneratorContextManager instance based on the docstring of the decorated function, and I believe that approach might work for property instances, too (rather than needing to hardcode the isinstance check into render_doc()). It may even handle some of the other currently hardcoded conditions in that list. |
|||
| msg201326 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2013年10月26日 08:08 | |
New changeset 09153a9a3bb9 by Nick Coghlan in branch 'default': Close #19330 by using public classes in contextlib http://hg.python.org/cpython/rev/09153a9a3bb9 |
|||
| msg201365 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2013年10月26日 14:49 | |
Issue 19031 is a report indicating that this is a problem for Enum instances as well. |
|||
| msg201388 - (view) | Author: Ethan Furman (ethan.furman) * (Python committer) | Date: 2013年10月26日 18:11 | |
Would it make sense to have the presence of a non-None __doc__ be a deciding factor? How often does an instance have a docstring where one would want the class info instead? |
|||
| msg201404 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2013年10月27日 01:32 | |
As far as I am aware, never. But "instance.__doc__" falls back to the class, hence the != check rather than "is not None". |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:52 | admin | set | github: 63603 |
| 2015年07月21日 08:07:37 | ethan.furman | set | nosy:
- ethan.furman |
| 2014年11月01日 14:54:07 | ethan.furman | link | issue19031 superseder |
| 2014年02月01日 00:11:48 | yselivanov | set | nosy:
+ yselivanov |
| 2013年10月27日 01:32:26 | ncoghlan | set | messages: + msg201404 |
| 2013年10月26日 18:11:09 | ethan.furman | set | messages: + msg201388 |
| 2013年10月26日 14:49:59 | ncoghlan | set | messages: + msg201365 |
| 2013年10月26日 08:08:29 | python-dev | set | nosy:
+ python-dev messages: + msg201326 |
| 2013年10月26日 07:22:18 | ncoghlan | create | |