mirror of
https://github.com/dgelessus/python-rsrcfork.git
synced 2024-11-25 19:31:44 +00:00
Fix more issues reported by mypy
This commit is contained in:
parent
b77c85c295
commit
e0f73d3220
@ -65,7 +65,7 @@ def _bytes_unescape(string: str) -> bytes:
|
||||
|
||||
return bytes(out)
|
||||
|
||||
def _bytes_escape(bs: bytes, *, quote: str=None) -> str:
|
||||
def _bytes_escape(bs: bytes, *, quote: typing.Optional[str]=None) -> str:
|
||||
"""Convert a bytestring to a string (using _TEXT_ENCODING), with non-printable characters hex-escaped.
|
||||
|
||||
(We implement our own escaping mechanism here to not depend on Python's str or bytes repr.)
|
||||
|
@ -4,6 +4,7 @@ import enum
|
||||
import io
|
||||
import os
|
||||
import struct
|
||||
import types
|
||||
import typing
|
||||
import warnings
|
||||
|
||||
@ -197,7 +198,7 @@ class Resource(object):
|
||||
else:
|
||||
return self.data_raw
|
||||
|
||||
class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]]):
|
||||
class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]], typing.ContextManager["ResourceFile"]):
|
||||
"""A resource file reader operating on a byte stream."""
|
||||
|
||||
# noinspection PyProtectedMember
|
||||
@ -274,7 +275,7 @@ class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]]):
|
||||
_references: typing.MutableMapping[bytes, typing.MutableMapping[int, typing.Tuple[int, ResourceAttrs, int]]]
|
||||
|
||||
@classmethod
|
||||
def open(cls, filename: typing.Union[str, os.PathLike], *, fork: str="auto", **kwargs) -> "ResourceFile":
|
||||
def open(cls, filename: typing.Union[str, os.PathLike], *, fork: str="auto", **kwargs: typing.Any) -> "ResourceFile":
|
||||
"""Open the file at the given path as a ResourceFile.
|
||||
|
||||
The fork parameter controls which fork of the file the resource data will be read from. It accepts the following values:
|
||||
@ -458,8 +459,14 @@ class ResourceFile(typing.Mapping[bytes, typing.Mapping[int, Resource]]):
|
||||
def __enter__(self) -> "ResourceFile":
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
|
||||
def __exit__(
|
||||
self,
|
||||
exc_type: typing.Optional[typing.Type[BaseException]],
|
||||
exc_val: typing.Optional[BaseException],
|
||||
exc_tb: typing.Optional[types.TracebackType]
|
||||
) -> typing.Optional[bool]:
|
||||
self.close()
|
||||
return None
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""Get the number of resource types in this ResourceFile."""
|
||||
|
@ -84,7 +84,7 @@ class CompressedApplicationHeaderInfo(CompressedHeaderInfo):
|
||||
self.working_buffer_fractional_size = working_buffer_fractional_size
|
||||
self.expansion_buffer_size = expansion_buffer_size
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return f"{type(self).__qualname__}(header_length={self.header_length}, compression_type=0x{self.compression_type:>04x}, decompressed_length={self.decompressed_length}, dcmp_id={self.dcmp_id}, working_buffer_fractional_size={self.working_buffer_fractional_size}, expansion_buffer_size={self.expansion_buffer_size})"
|
||||
|
||||
|
||||
@ -96,7 +96,7 @@ class CompressedSystemHeaderInfo(CompressedHeaderInfo):
|
||||
|
||||
self.parameters = parameters
|
||||
|
||||
def __repr__(self):
|
||||
def __repr__(self) -> str:
|
||||
return f"{type(self).__qualname__}(header_length={self.header_length}, compression_type=0x{self.compression_type:>04x}, decompressed_length={self.decompressed_length}, dcmp_id={self.dcmp_id}, parameters={self.parameters!r})"
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user