python / python/typeshed

`ZipFile.open()` return type

Open
#13,051 1 comment 0 reactions 0 assignees View on GitHub

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

ZipFile.open() returns an instance of ZipExtFile if mode='r' and an instance of _ZipWriteFile if mode='w', but in typeshed its return type is IO[bytes].

https://github.com/python/typeshed/blob/1cbfc7532544e3220c719c31922bab759d29acfe/stdlib/zipfile/__init__.pyi#L228-L230

Is this on purpose? Would it be possible instead to have an overload for each case?

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

Read stdlib/zipfile/init.pyi at the cited return annotation and compare it with the linked CPython ZipFile.open(), ZipExtFile, and _ZipWriteFile definitions. Done means the typeshed annotation distinguishes the read and write modes with appropriate overloads, if the comparison supports that change.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.