diff --git a/mypy/main.py b/mypy/main.py index c657f09e2600..ae7a3b9d5c86 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -11,7 +11,7 @@ from collections.abc import Sequence from gettext import gettext from io import TextIOWrapper -from typing import IO, Any, Final, NoReturn, Protocol, TextIO +from typing import IO, TYPE_CHECKING, Any, Final, NoReturn, TextIO from mypy import build, defaults, state, util from mypy.config_parser import ( @@ -36,9 +36,8 @@ from mypy.split_namespace import SplitNamespace from mypy.version import __version__ - -class _SupportsWrite(Protocol): - def write(self, s: str, /) -> object: ... +if TYPE_CHECKING: + from _typeshed import SupportsWrite orig_stat: Final = os.stat @@ -378,17 +377,17 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # ===================== # Help-printing methods # ===================== - def print_usage(self, file: _SupportsWrite | None = None) -> None: + def print_usage(self, file: SupportsWrite[str] | None = None) -> None: if file is None: file = self.stdout self._print_message(self.format_usage(), file) - def print_help(self, file: _SupportsWrite | None = None) -> None: + def print_help(self, file: SupportsWrite[str] | None = None) -> None: if file is None: file = self.stdout self._print_message(self.format_help(), file) - def _print_message(self, message: str, file: _SupportsWrite | None = None) -> None: + def _print_message(self, message: str, file: SupportsWrite[str] | None = None) -> None: if message: if file is None: file = self.stderr