python / python/typeshed

subprocess stdout read1

Open Beginner friendly
#6,153 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stubs: false positive topic: io
Dominant language
Python
Stars
5.1k
Forks
2.1k
Avg merge
1d 19h
Merged PRs (30d)
82

Description

import subprocess
process = subprocess.Popen("echo hello", shell=True, stdout=subprocess.PIPE)
assert process.stdout is not None
print(process.stdout.read1())

mypy error:

asd.py:4: error: "IO[bytes]" has no attribute "read1"; maybe "read"?
Found 1 error in 1 file (checked 1 source file)

But at runtime there is read1() method. It is useful because unlike read(), it will return the output as soon as it is available, instead of reading more until it gets n bytes or end of file.

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.

Research direction

Locate the subprocess.Popen stdout stub and inspect how its stream type is declared. Reproduce the issue with the provided Python snippet, then verify that mypy accepts read1() on process.stdout without losing the existing stdout typing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.