`AbstractContextManger.__enter__` should be abstract
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
Code sample in basedpyright playground
from contextlib import AbstractContextManager
from typing import override
class CM(AbstractContextManager[int]):
@override
def __exit__(self, *_): ...
with CM() as i:
print(i + 1)
AbstractContextManger.__enter__ has a default implementation that returns self, so by making it abstract you would require implementations to provide the correct implementation. this would force a redundant implementation if the type is Self, but that is currently impossible to type anyway: https://discuss.python.org/t/self-as-typevar-default/90939
even without Self support, it is only one line of redundant code: def __enter__(self) -> Self: return self
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the basedpyright playground example and the AbstractContextManager stub entry point it exercises. Check how the current default enter affects abstract-class checking, then verify that making it abstract requires an implementation while preserving the intended context-manager typing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100