sys.stdout.buffer has incorrect type?
Open
Nobody has claimed this yet.
topic: io
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
mypy test.py
test.py:10: error: Argument 1 to "test" has incompatible type "BinaryIO"; expected "BufferedIOBase"
cat test.py
import io
import sys
class C(io.BufferedIOBase):
pass
def test(c: io.BufferedIOBase):
assert isinstance(c, io.BufferedIOBase)
test(sys.stdout.buffer)
test(C())
python3 test.py
As we can see the isinstance check passes but mypy asserts
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 by running the mypy command against the test.py reproduction and inspect the Python standard-library stubs for the sys.stdout.buffer entry point. Compare its declared type with the runtime isinstance result, then verify the corrected behavior by rerunning mypy on the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100