Merge pull request #3264 from pre-commit/pre-commit-ci-update-config

[pre-commit.ci] pre-commit autoupdate
This commit is contained in:
Anthony Sottile 2024-07-28 15:07:33 -04:00 committed by GitHub
commit f641f6a157
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 22 deletions

View file

@ -37,8 +37,8 @@ repos:
hooks: hooks:
- id: flake8 - id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1 rev: v1.11.0
hooks: hooks:
- id: mypy - id: mypy
additional_dependencies: [types-all] additional_dependencies: [types-pyyaml]
exclude: ^testing/resources/ exclude: ^testing/resources/

View file

@ -205,7 +205,7 @@ else: # pragma: no cover
def _handle_readonly( def _handle_readonly(
func: Callable[[str], object], func: Callable[[str], object],
path: str, path: str,
exc: Exception, exc: BaseException,
) -> None: ) -> None:
if ( if (
func in (os.rmdir, os.remove, os.unlink) and func in (os.rmdir, os.remove, os.unlink) and
@ -223,7 +223,7 @@ if sys.version_info < (3, 12): # pragma: <3.12 cover
def _handle_readonly_old( def _handle_readonly_old(
func: Callable[[str], object], func: Callable[[str], object],
path: str, path: str,
excinfo: tuple[type[Exception], Exception, TracebackType], excinfo: tuple[type[BaseException], BaseException, TracebackType],
) -> None: ) -> None:
return _handle_readonly(func, path, excinfo[1]) return _handle_readonly(func, path, excinfo[1])

View file

@ -209,36 +209,25 @@ def log_info_mock():
yield mck yield mck
class FakeStream:
def __init__(self):
self.data = io.BytesIO()
def write(self, s):
self.data.write(s)
def flush(self):
pass
class Fixture: class Fixture:
def __init__(self, stream): def __init__(self, stream: io.BytesIO) -> None:
self._stream = stream self._stream = stream
def get_bytes(self): def get_bytes(self) -> bytes:
"""Get the output as-if no encoding occurred""" """Get the output as-if no encoding occurred"""
data = self._stream.data.getvalue() data = self._stream.getvalue()
self._stream.data.seek(0) self._stream.seek(0)
self._stream.data.truncate() self._stream.truncate()
return data.replace(b'\r\n', b'\n') return data.replace(b'\r\n', b'\n')
def get(self): def get(self) -> str:
"""Get the output assuming it was written as UTF-8 bytes""" """Get the output assuming it was written as UTF-8 bytes"""
return self.get_bytes().decode() return self.get_bytes().decode()
@pytest.fixture @pytest.fixture
def cap_out(): def cap_out():
stream = FakeStream() stream = io.BytesIO()
write = functools.partial(output.write, stream=stream) write = functools.partial(output.write, stream=stream)
write_line_b = functools.partial(output.write_line_b, stream=stream) write_line_b = functools.partial(output.write_line_b, stream=stream)
with mock.patch.multiple(output, write=write, write_line_b=write_line_b): with mock.patch.multiple(output, write=write, write_line_b=write_line_b):