55
55
import struct
56
56
import copy
57
57
import io
58
- from typing import cast
58
+ from typing import IO , TYPE_CHECKING , Any , cast
59
59
60
60
import six
61
61
62
+ if TYPE_CHECKING :
63
+ from bz2 import _ReadBinaryMode , _WriteBinaryMode
64
+ from gzip import GzipFile
65
+
62
66
if sys .platform == 'mac' :
63
67
# This module needs work for MacOS9, especially in the area of pathname
64
68
# handling. In many places it is assumed a simple substitution of / by the
@@ -557,6 +561,7 @@ class which (unlike gzip.GzipFile) has no support for
557
561
"""
558
562
559
563
def __init__ (self , fileobj , mode ):
564
+ # type:(IO[Any], _ReadBinaryMode | _WriteBinaryMode) -> None
560
565
_CMPProxy .__init__ (self , fileobj , mode )
561
566
self .init ()
562
567
@@ -1069,6 +1074,7 @@ def open(cls, name=None, mode="r", fileobj=None, bufsize=20*512):
1069
1074
1070
1075
@classmethod
1071
1076
def cpioopen (cls , name , mode = "r" , fileobj = None ):
1077
+ # type:(str, _ReadBinaryMode | _WriteBinaryMode, IO[Any] | GzipFile | None) -> CpioFile
1072
1078
"""Open uncompressed cpio archive name for reading or writing.
1073
1079
"""
1074
1080
if len (mode ) > 1 or mode not in "raw" :
@@ -1100,6 +1106,7 @@ def gzopen(cls, name, mode="r", fileobj=None, compresslevel=9):
1100
1106
1101
1107
@classmethod
1102
1108
def bz2open (cls , name , mode = "r" , fileobj = None , compresslevel = 9 ):
1109
+ # type:(str, _ReadBinaryMode | _WriteBinaryMode, IO[Any] | None, int) -> CpioFile
1103
1110
"""Open bzip2 compressed cpio archive name for reading or writing.
1104
1111
Appending is not allowed.
1105
1112
"""
@@ -1112,7 +1119,7 @@ def bz2open(cls, name, mode="r", fileobj=None, compresslevel=9):
1112
1119
raise CompressionError ("bz2 module is not available" )
1113
1120
1114
1121
if fileobj is not None :
1115
- fileobj = _BZ2Proxy (fileobj , mode )
1122
+ fileobj = cast ( IO [ Any ], _BZ2Proxy (fileobj , mode )) # pragma: no cover
1116
1123
else :
1117
1124
fileobj = bz2 .BZ2File (name , mode , compresslevel = compresslevel )
1118
1125
0 commit comments