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

Open
#97,699 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
documentation

Research direction

Start with the Python data model documentation sections for object.enter and object.exit linked in the issue, and verify their current wording against Python 3.10.3. Update the documentation to clarify that these methods are not defined on object and explain that context manager objects define them to provide the interface; done means the documented behavior matches the runtime.

Written by the indexing model from the issue text.

Description

docs

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!

Dominant language
Python
Stars
77.2k
Forks
36k
Avg merge
1d 9h
Merged PRs (30d)
558

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/cpython

All issues in python/cpython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.