Skip to content

Commit

Permalink
some pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroPasotti committed Jun 13, 2022
1 parent 37f71a7 commit 51700c7
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions ops/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class _Writable(Protocol):
# but we can't import that type
def write(self, buf: Union[bytes, str, bytearray]) -> int: ... # noqa

_AnyStrFileLikeIO = typing.Union[_FileLikeIO[bytes], _FileLikeIO[str]]
_AnyStrFileLikeIO = Union[_FileLikeIO[bytes], _FileLikeIO[str]]
_TextOrBinaryIO = Union[TextIO, BinaryIO]
_IOSource = Union[str, bytes, _AnyStrFileLikeIO]
_PartType = Literal['response', 'files']
_Ctype = Literal['multipart/form-data', 'application/json']
Expand Down Expand Up @@ -2184,8 +2185,8 @@ def exec(
group_id: Optional[int] = None,
group: Optional[str] = None,
stdin: Optional['_IOSource'] = None,
stdout: Optional[Union[TextIO, BinaryIO]] = None,
stderr: Optional[Union[TextIO, BinaryIO]] = None,
stdout: Optional['_TextOrBinaryIO'] = None,
stderr: Optional['_TextOrBinaryIO'] = None,
encoding: Optional[str] = 'utf-8',
combine_stderr: bool = False
) -> ExecProcess:
Expand Down Expand Up @@ -2584,24 +2585,24 @@ def _prepare_tempfile(self, filename: str):
def _get_open_tempfile(self):
return self._files[self.current_filename]

def get_response(self) -> '_FilesResponse':
def get_response(self) -> Optional['_FilesResponse']:
"""Return the deserialized JSON object from the multipart "response" field."""
assert self._response, 'response unset'
return self._response

def filenames(self):
"""Return a list of filenames from the "files" parts of the response."""
return list(self._files.keys())

def get_file(self, path: str, encoding: Optional[str]) -> Union[TextIO, BinaryIO]:
def get_file(self, path: str, encoding: Optional[str]) -> '_TextOrBinaryIO':
"""Return an open file object containing the data."""
mode = 'r' if encoding else 'rb'
# We're using text-based file I/O purely for file encoding purposes, not for
# newline normalization. newline='' serves the line endings as-is.
newline = '' if encoding else None
return open(self._files[path].name, mode, # type: ignore
encoding=encoding, newline=newline)

file_io = open(self._files[path].name, mode,
encoding=encoding, newline=newline)
# open() returns IO[Any]
return typing.cast('_TextOrBinaryIO', file_io)

class _MultipartParser:
def __init__(
Expand Down

0 comments on commit 51700c7

Please # to comment.