Skip to content

Commit

Permalink
Bump linters
Browse files Browse the repository at this point in the history
- mypy to 1.6.0
- pylint to 3.0.1
- flake8 to 6.1.0
- pin yamllint
  • Loading branch information
Shrews committed Oct 17, 2023
1 parent 60cfaa1 commit acc9fdb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
37 changes: 14 additions & 23 deletions src/ansible_runner/utils/base64io.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
_LOGGER = logging.getLogger(LOGGER_NAME)


def _to_bytes(data):
# type: (AnyStr) -> bytes
def _to_bytes(data: AnyStr) -> bytes:
"""Convert input data from either string or bytes to bytes.
:param data: Data to convert
Expand Down Expand Up @@ -74,8 +73,7 @@ class Base64IO(io.IOBase):

closed = False

def __init__(self, wrapped):
# type: (Base64IO, IO) -> None
def __init__(self, wrapped: IO) -> None:
"""Check for required methods on wrapped stream and set up read buffer.
:raises TypeError: if ``wrapped`` does not have attributes needed to determine the stream's state
Expand All @@ -91,17 +89,17 @@ def __init__(self, wrapped):
self.__write_buffer = b""

def __enter__(self):
# type: () -> Base64IO
"""Return self on enter."""
return self

def __exit__(self, exc_type, exc_value, traceback):
# type: (Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]) -> None
def __exit__(self,
exc_type: Optional[Type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType]) -> None:
"""Properly close self on exit."""
self.close()

def close(self):
# type: () -> None
def close(self) -> None:
"""Close this stream, encoding and writing any buffered bytes is present.
.. note::
Expand All @@ -113,8 +111,7 @@ def close(self):
self.__write_buffer = b""
self.closed = True

def _passthrough_interactive_check(self, method_name):
# type: (str) -> bool
def _passthrough_interactive_check(self, method_name: str) -> bool:
"""Attempt to call the specified method on the wrapped stream and return the result.
If the method is not found on the wrapped stream, return False.
Expand All @@ -128,8 +125,7 @@ def _passthrough_interactive_check(self, method_name):
return False
return method()

def writable(self):
# type: () -> bool
def writable(self) -> bool:
"""Determine if the stream can be written to.
Delegates to wrapped stream when possible.
Expand All @@ -139,8 +135,7 @@ def writable(self):
"""
return self._passthrough_interactive_check("writable")

def readable(self):
# type: () -> bool
def readable(self) -> bool:
"""Determine if the stream can be read from.
Delegates to wrapped stream when possible.
Expand All @@ -150,13 +145,11 @@ def readable(self):
"""
return self._passthrough_interactive_check("readable")

def flush(self):
# type: () -> None
def flush(self) -> None:
"""Flush the write buffer of the wrapped stream."""
return self.__wrapped.flush()

def write(self, b):
# type: (bytes) -> int
def write(self, b: bytes) -> int:
"""Base64-encode the bytes and write them to the wrapped stream.
Any bytes that would require padding for the next write call are buffered until the
Expand Down Expand Up @@ -191,8 +184,7 @@ def write(self, b):
self.__write_buffer = _bytes_to_write[trailing_byte_pos:]
return self.__wrapped.write(base64.b64encode(_bytes_to_write[:trailing_byte_pos]))

def _read_additional_data_removing_whitespace(self, data, total_bytes_to_read):
# type: (bytes, int) -> bytes
def _read_additional_data_removing_whitespace(self, data: bytes, total_bytes_to_read: int) -> bytes:
"""Read additional data from wrapped stream until we reach the desired number of bytes.
.. note::
Expand Down Expand Up @@ -224,8 +216,7 @@ def _read_additional_data_removing_whitespace(self, data, total_bytes_to_read):
_remaining_bytes_to_read = total_bytes_to_read - _data_buffer.tell()
return _data_buffer.getvalue()

def read(self, b=-1):
# type: (int) -> bytes
def read(self, b=-1) -> bytes:
"""Read bytes from wrapped stream, base64-decoding before return.
.. note::
Expand Down
8 changes: 4 additions & 4 deletions test/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mypy==1.3.0
pylint==2.17.4
mypy==1.6.0
pylint==3.0.1
pytest==7.1.2
pytest-cov
pytest-mock
pytest-timeout
pytest-xdist==2.5.0
types-pyyaml
flake8==4.0.1
yamllint
flake8==6.1.0
yamllint==1.32.0
cryptography

0 comments on commit acc9fdb

Please sign in to comment.