Skip to content

Commit 54ad048

Browse files
committed
Enable check_untyped_defs mypy option for testing/ too
1 parent 71dfdca commit 54ad048

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+598
-443
lines changed

setup.cfg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ formats = sdist.tgz,bdist_wheel
9191

9292
[mypy]
9393
mypy_path = src
94+
check_untyped_defs = True
9495
ignore_missing_imports = True
9596
no_implicit_optional = True
9697
show_error_codes = True
9798
strict_equality = True
9899
warn_redundant_casts = True
99100
warn_return_any = True
100101
warn_unused_configs = True
101-
102-
[mypy-_pytest.*]
103-
check_untyped_defs = True

src/_pytest/_code/code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from typing import Generic
1616
from typing import Iterable
1717
from typing import List
18+
from typing import Mapping
1819
from typing import Optional
1920
from typing import Pattern
2021
from typing import Sequence
@@ -728,7 +729,7 @@ def get_exconly(
728729
failindent = indentstr
729730
return lines
730731

731-
def repr_locals(self, locals: Dict[str, object]) -> Optional["ReprLocals"]:
732+
def repr_locals(self, locals: Mapping[str, object]) -> Optional["ReprLocals"]:
732733
if self.showlocals:
733734
lines = []
734735
keys = [loc for loc in locals if loc[0] != "@"]

src/_pytest/logging.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class PercentStyleMultiline(logging.PercentStyle):
9696
formats the message as if each line were logged separately.
9797
"""
9898

99-
def __init__(self, fmt: str, auto_indent: Union[int, str, bool]) -> None:
99+
def __init__(self, fmt: str, auto_indent: Union[int, str, bool, None]) -> None:
100100
super().__init__(fmt)
101101
self._auto_indent = self._get_auto_indent(auto_indent)
102102

@@ -109,7 +109,7 @@ def _update_message(
109109
return tmp
110110

111111
@staticmethod
112-
def _get_auto_indent(auto_indent_option: Union[int, str, bool]) -> int:
112+
def _get_auto_indent(auto_indent_option: Union[int, str, bool, None]) -> int:
113113
"""Determines the current auto indentation setting
114114
115115
Specify auto indent behavior (on/off/fixed) by passing in
@@ -139,7 +139,9 @@ def _get_auto_indent(auto_indent_option: Union[int, str, bool]) -> int:
139139
>0 (explicitly set indentation position).
140140
"""
141141

142-
if type(auto_indent_option) is int:
142+
if auto_indent_option is None:
143+
return 0
144+
elif type(auto_indent_option) is int:
143145
return int(auto_indent_option)
144146
elif type(auto_indent_option) is str:
145147
try:
@@ -732,7 +734,9 @@ class _LiveLoggingStreamHandler(logging.StreamHandler):
732734
stream = None # type: TerminalReporter # type: ignore
733735

734736
def __init__(
735-
self, terminal_reporter: TerminalReporter, capture_manager: CaptureManager
737+
self,
738+
terminal_reporter: TerminalReporter,
739+
capture_manager: Optional[CaptureManager],
736740
) -> None:
737741
"""
738742
:param _pytest.terminal.TerminalReporter terminal_reporter:

src/_pytest/pytester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def _sys_snapshot():
401401

402402

403403
@pytest.fixture
404-
def _config_for_test():
404+
def _config_for_test() -> Generator[Config, None, None]:
405405
from _pytest.config import get_config
406406

407407
config = get_config()

src/_pytest/python_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ def raises( # noqa: F811
712712
fail(message)
713713

714714

715+
# This doesn't work with mypy for now. Use fail.Exception instead.
715716
raises.Exception = fail.Exception # type: ignore
716717

717718

0 commit comments

Comments
 (0)