Skip to content

Commit

Permalink
Use SupportsWrite protocol from typeshed (#18404)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Jan 3, 2025
1 parent 8456287 commit bac9984
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bac9984

Please sign in to comment.