|
10 | 10 | from collections import defaultdict
|
11 | 11 | from gettext import gettext
|
12 | 12 | from io import TextIOWrapper
|
13 |
| -from typing import IO, Any, Final, NoReturn, Sequence, TextIO |
| 13 | +from typing import IO, Any, Final, NoReturn, Protocol, Sequence, TextIO |
14 | 14 |
|
15 | 15 | from mypy import build, defaults, state, util
|
16 | 16 | from mypy.config_parser import (
|
|
35 | 35 | from mypy.split_namespace import SplitNamespace
|
36 | 36 | from mypy.version import __version__
|
37 | 37 |
|
| 38 | + |
| 39 | +class _SupportsWrite(Protocol): |
| 40 | + def write(self, s: str, /) -> object: ... |
| 41 | + |
| 42 | + |
38 | 43 | orig_stat: Final = os.stat
|
39 | 44 | MEM_PROFILE: Final = False # If True, dump memory profile
|
40 | 45 |
|
@@ -372,17 +377,17 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
|
372 | 377 | # =====================
|
373 | 378 | # Help-printing methods
|
374 | 379 | # =====================
|
375 |
| - def print_usage(self, file: IO[str] | None = None) -> None: |
| 380 | + def print_usage(self, file: _SupportsWrite | None = None) -> None: |
376 | 381 | if file is None:
|
377 | 382 | file = self.stdout
|
378 | 383 | self._print_message(self.format_usage(), file)
|
379 | 384 |
|
380 |
| - def print_help(self, file: IO[str] | None = None) -> None: |
| 385 | + def print_help(self, file: _SupportsWrite | None = None) -> None: |
381 | 386 | if file is None:
|
382 | 387 | file = self.stdout
|
383 | 388 | self._print_message(self.format_help(), file)
|
384 | 389 |
|
385 |
| - def _print_message(self, message: str, file: IO[str] | None = None) -> None: |
| 390 | + def _print_message(self, message: str, file: _SupportsWrite | None = None) -> None: |
386 | 391 | if message:
|
387 | 392 | if file is None:
|
388 | 393 | file = self.stderr
|
|
0 commit comments