Skip to content

Commit fa77992

Browse files
committed
Enable check_untyped_defs mypy option for testing/ too
1 parent 3eea787 commit fa77992

38 files changed

+589
-439
lines changed

setup.cfg

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

6464
[mypy]
6565
mypy_path = src
66+
check_untyped_defs = True
6667
ignore_missing_imports = True
6768
no_implicit_optional = True
6869
show_error_codes = True
6970
strict_equality = True
7071
warn_redundant_casts = True
7172
warn_return_any = True
7273
warn_unused_configs = True
73-
74-
[mypy-_pytest.*]
75-
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
@@ -739,7 +740,7 @@ def get_exconly(
739740
failindent = indentstr
740741
return lines
741742

742-
def repr_locals(self, locals: Dict[str, object]) -> Optional["ReprLocals"]:
743+
def repr_locals(self, locals: Mapping[str, object]) -> Optional["ReprLocals"]:
743744
if self.showlocals:
744745
lines = []
745746
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:
@@ -781,7 +783,9 @@ class _LiveLoggingStreamHandler(logging.StreamHandler):
781783
stream = None # type: TerminalReporter # type: ignore
782784

783785
def __init__(
784-
self, terminal_reporter: TerminalReporter, capture_manager: CaptureManager
786+
self,
787+
terminal_reporter: TerminalReporter,
788+
capture_manager: Optional[CaptureManager],
785789
) -> None:
786790
"""
787791
:param _pytest.terminal.TerminalReporter terminal_reporter:

src/_pytest/pytester.py

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

401401

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

406406
config = get_config()

src/_pytest/python_api.py

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

712712

713+
# This doesn't work with mypy for now. Use fail.Exception instead.
713714
raises.Exception = fail.Exception # type: ignore
714715

715716

0 commit comments

Comments
 (0)