zipfile: improve bytes handling (#9109)

Technically some uses of `pwd` accept more types, but others
use `isinstance()` to enforce only `bytes`. It seems better to
keep the same type throughout the module.
This commit is contained in:
Jelle Zijlstra
2022-11-06 21:16:27 -08:00
committed by GitHub
parent 6639e2e14c
commit 1d4eed1c9d

View File

@@ -1,6 +1,6 @@
import io
import sys
from _typeshed import Self, StrOrBytesPath, StrPath
from _typeshed import Self, StrOrBytesPath, StrPath, _BufferWithLen
from collections.abc import Callable, Iterable, Iterator
from os import PathLike
from types import TracebackType
@@ -103,7 +103,7 @@ class ZipFile:
compression: int # undocumented
compresslevel: int | None # undocumented
mode: _ZipFileMode # undocumented
pwd: str | None # undocumented
pwd: bytes | None # undocumented
if sys.version_info >= (3, 11):
@overload
def __init__(
@@ -173,7 +173,11 @@ class ZipFile:
self, filename: StrPath, arcname: StrPath | None = ..., compress_type: int | None = ..., compresslevel: int | None = ...
) -> None: ...
def writestr(
self, zinfo_or_arcname: str | ZipInfo, data: bytes | str, compress_type: int | None = ..., compresslevel: int | None = ...
self,
zinfo_or_arcname: str | ZipInfo,
data: _BufferWithLen | str,
compress_type: int | None = ...,
compresslevel: int | None = ...,
) -> None: ...
if sys.version_info >= (3, 11):
def mkdir(self, zinfo_or_directory_name: str | ZipInfo, mode: int = ...) -> None: ...