python / python/cpython

object doesn't have an __enter__/__exit__ yet docs say it does

未关闭
#97,699 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

docs
主要语言
Python
星标
77.2k
派生
36k
平均合并
1 天 9 小时
30 天内合并 PR
558

描述

Documentation

Here's the current docs in the Python data model on object.__enter__:

object.__enter__(self)

And object.__exit__:

object.__exit__(self, exc_type, exc_value, traceback)

However, with Python 3.10.3, we see neither of these methods belong to object:

>>> object.__enter__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'object' has no attribute '__enter__'. Did you mean: '__ne__'?
>>> object.__exit__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'object' has no attribute '__exit__'. Did you mean: '__init__'?

I think the docs could be:

  • More clear that __enter__ and __exit__ are not methods on object
  • Mention where they come from (just being defined within your object to match the interface)

Thank you for your consideration!

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中链接的 Python 数据模型文档里关于 object.enter 和 object.exit 的章节开始,并根据 Python 3.10.3 核对其当前措辞。更新文档,明确这些方法并未在 object 上定义,并说明上下文管理器对象会定义它们以提供该接口;当文档描述的行为与运行时行为一致时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
documentation
Issue 类型
文档
难度
2/5
预计耗时
1-3 小时
活跃度
停滞
描述清晰度
描述清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。