Skip to content

Commit d39780f

Browse files
authored
Merge pull request #9428 from pytest-dev/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2 parents 443aa02 + c69b84f commit d39780f

File tree

9 files changed

+24
-17
lines changed

9 files changed

+24
-17
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ repos:
4848
hooks:
4949
- id: python-use-type-annotations
5050
- repo: https://github.com/pre-commit/mirrors-mypy
51-
rev: v0.910-1
51+
rev: v0.920
5252
hooks:
5353
- id: mypy
5454
files: ^(src/|testing/)

src/_pytest/capture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _reopen_stdio(f, mode):
112112
buffering = -1
113113

114114
return io.TextIOWrapper(
115-
open(os.dup(f.fileno()), mode, buffering), # type: ignore[arg-type]
115+
open(os.dup(f.fileno()), mode, buffering),
116116
f.encoding,
117117
f.errors,
118118
f.newlines,

src/_pytest/junitxml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def __init__(self, nodeid: Union[str, TestReport], xml: "LogXML") -> None:
9292
self.xml = xml
9393
self.add_stats = self.xml.add_stats
9494
self.family = self.xml.family
95-
self.duration = 0
95+
self.duration = 0.0
9696
self.properties: List[Tuple[str, str]] = []
9797
self.nodes: List[ET.Element] = []
9898
self.attrs: Dict[str, str] = {}

src/_pytest/logging.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Access and control log capturing."""
2+
import io
23
import logging
34
import os
45
import re
@@ -13,6 +14,7 @@
1314
from typing import Mapping
1415
from typing import Optional
1516
from typing import Tuple
17+
from typing import TYPE_CHECKING
1618
from typing import TypeVar
1719
from typing import Union
1820

@@ -34,6 +36,11 @@
3436
from _pytest.stash import StashKey
3537
from _pytest.terminal import TerminalReporter
3638

39+
if TYPE_CHECKING:
40+
logging_StreamHandler = logging.StreamHandler[StringIO]
41+
else:
42+
logging_StreamHandler = logging.StreamHandler
43+
3744

3845
DEFAULT_LOG_FORMAT = "%(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)s"
3946
DEFAULT_LOG_DATE_FORMAT = "%H:%M:%S"
@@ -322,11 +329,9 @@ def __exit__(self, type, value, traceback):
322329
root_logger.removeHandler(self.handler)
323330

324331

325-
class LogCaptureHandler(logging.StreamHandler):
332+
class LogCaptureHandler(logging_StreamHandler):
326333
"""A logging handler that stores log records and the log text."""
327334

328-
stream: StringIO
329-
330335
def __init__(self) -> None:
331336
"""Create a new log handler."""
332337
super().__init__(StringIO())
@@ -621,7 +626,8 @@ def set_log_path(self, fname: str) -> None:
621626
if not fpath.parent.exists():
622627
fpath.parent.mkdir(exist_ok=True, parents=True)
623628

624-
stream = fpath.open(mode="w", encoding="UTF-8")
629+
# https://github.com/python/mypy/issues/11193
630+
stream: io.TextIOWrapper = fpath.open(mode="w", encoding="UTF-8") # type: ignore[assignment]
625631
if sys.version_info >= (3, 7):
626632
old_stream = self.log_file_handler.setStream(stream)
627633
else:
@@ -633,8 +639,7 @@ def set_log_path(self, fname: str) -> None:
633639
finally:
634640
self.log_file_handler.release()
635641
if old_stream:
636-
# https://github.com/python/typeshed/pull/5663
637-
old_stream.close() # type:ignore[attr-defined]
642+
old_stream.close()
638643

639644
def _log_cli_enabled(self):
640645
"""Return whether live logging is enabled."""
@@ -758,7 +763,7 @@ def handleError(self, record: logging.LogRecord) -> None:
758763
pass
759764

760765

761-
class _LiveLoggingStreamHandler(logging.StreamHandler):
766+
class _LiveLoggingStreamHandler(logging_StreamHandler):
762767
"""A logging StreamHandler used by the live logging feature: it will
763768
write a newline before the first log message in each test.
764769

testing/code/test_source.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ def test_findsource(monkeypatch) -> None:
332332
lines = ["if 1:\n", " def x():\n", " pass\n"]
333333
co = compile("".join(lines), filename, "exec")
334334

335-
# Type ignored because linecache.cache is private.
336-
monkeypatch.setitem(linecache.cache, filename, (1, None, lines, filename)) # type: ignore[attr-defined]
335+
monkeypatch.setitem(linecache.cache, filename, (1, None, lines, filename))
337336

338337
src, lineno = findsource(co)
339338
assert src is not None

testing/test_assertrewrite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ def atomic_write_failed(fn, mode="r", overwrite=False):
10571057
e = OSError()
10581058
e.errno = 10
10591059
raise e
1060-
yield # type:ignore[unreachable]
1060+
yield
10611061

10621062
monkeypatch.setattr(
10631063
_pytest.assertion.rewrite, "atomic_write", atomic_write_failed

testing/test_legacypath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_item_fspath(pytester: pytest.Pytester) -> None:
1414
items2, hookrec = pytester.inline_genitems(item.nodeid)
1515
(item2,) = items2
1616
assert item2.name == item.name
17-
assert item2.fspath == item.fspath # type: ignore[attr-defined]
17+
assert item2.fspath == item.fspath
1818
assert item2.path == item.path
1919

2020

testing/test_pastebin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import email.message
12
import io
23
from typing import List
34
from typing import Union
@@ -98,7 +99,9 @@ def mocked_urlopen_fail(self, monkeypatch: MonkeyPatch):
9899

99100
def mocked(url, data):
100101
calls.append((url, data))
101-
raise urllib.error.HTTPError(url, 400, "Bad request", {}, io.BytesIO())
102+
raise urllib.error.HTTPError(
103+
url, 400, "Bad request", email.message.Message(), io.BytesIO()
104+
)
102105

103106
monkeypatch.setattr(urllib.request, "urlopen", mocked)
104107
return calls

testing/test_recwarn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ def test_deprecated_call_preserves(self) -> None:
114114
# Type ignored because `onceregistry` and `filters` are not
115115
# documented API.
116116
onceregistry = warnings.onceregistry.copy() # type: ignore
117-
filters = warnings.filters[:] # type: ignore
117+
filters = warnings.filters[:]
118118
warn = warnings.warn
119119
warn_explicit = warnings.warn_explicit
120120
self.test_deprecated_call_raises()
121121
self.test_deprecated_call()
122122
assert onceregistry == warnings.onceregistry # type: ignore
123-
assert filters == warnings.filters # type: ignore
123+
assert filters == warnings.filters
124124
assert warn is warnings.warn
125125
assert warn_explicit is warnings.warn_explicit
126126

0 commit comments

Comments
 (0)