Skip to content

Commit bac9984

Browse files
authored
Use SupportsWrite protocol from typeshed (#18404)
1 parent 8456287 commit bac9984

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

mypy/main.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from collections.abc import Sequence
1212
from gettext import gettext
1313
from io import TextIOWrapper
14-
from typing import IO, Any, Final, NoReturn, Protocol, TextIO
14+
from typing import IO, TYPE_CHECKING, Any, Final, NoReturn, TextIO
1515

1616
from mypy import build, defaults, state, util
1717
from mypy.config_parser import (
@@ -36,9 +36,8 @@
3636
from mypy.split_namespace import SplitNamespace
3737
from mypy.version import __version__
3838

39-
40-
class _SupportsWrite(Protocol):
41-
def write(self, s: str, /) -> object: ...
39+
if TYPE_CHECKING:
40+
from _typeshed import SupportsWrite
4241

4342

4443
orig_stat: Final = os.stat
@@ -378,17 +377,17 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
378377
# =====================
379378
# Help-printing methods
380379
# =====================
381-
def print_usage(self, file: _SupportsWrite | None = None) -> None:
380+
def print_usage(self, file: SupportsWrite[str] | None = None) -> None:
382381
if file is None:
383382
file = self.stdout
384383
self._print_message(self.format_usage(), file)
385384

386-
def print_help(self, file: _SupportsWrite | None = None) -> None:
385+
def print_help(self, file: SupportsWrite[str] | None = None) -> None:
387386
if file is None:
388387
file = self.stdout
389388
self._print_message(self.format_help(), file)
390389

391-
def _print_message(self, message: str, file: _SupportsWrite | None = None) -> None:
390+
def _print_message(self, message: str, file: SupportsWrite[str] | None = None) -> None:
392391
if message:
393392
if file is None:
394393
file = self.stderr

0 commit comments

Comments
 (0)