Skip to content

Commit

Permalink
ArgumentParser: use broader file type (#18354)
Browse files Browse the repository at this point in the history
This is in anticipation of python/typeshed#13324
  • Loading branch information
hamdanal authored Dec 28, 2024
1 parent 44bf7e5 commit a07ccf7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from collections import defaultdict
from gettext import gettext
from io import TextIOWrapper
from typing import IO, Any, Final, NoReturn, Sequence, TextIO
from typing import IO, Any, Final, NoReturn, Protocol, Sequence, TextIO

from mypy import build, defaults, state, util
from mypy.config_parser import (
Expand All @@ -35,6 +35,11 @@
from mypy.split_namespace import SplitNamespace
from mypy.version import __version__


class _SupportsWrite(Protocol):
def write(self, s: str, /) -> object: ...


orig_stat: Final = os.stat
MEM_PROFILE: Final = False # If True, dump memory profile

Expand Down Expand Up @@ -372,17 +377,17 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
# =====================
# Help-printing methods
# =====================
def print_usage(self, file: IO[str] | None = None) -> None:
def print_usage(self, file: _SupportsWrite | None = None) -> None:
if file is None:
file = self.stdout
self._print_message(self.format_usage(), file)

def print_help(self, file: IO[str] | None = None) -> None:
def print_help(self, file: _SupportsWrite | None = None) -> None:
if file is None:
file = self.stdout
self._print_message(self.format_help(), file)

def _print_message(self, message: str, file: IO[str] | None = None) -> None:
def _print_message(self, message: str, file: _SupportsWrite | None = None) -> None:
if message:
if file is None:
file = self.stderr
Expand Down

0 comments on commit a07ccf7

Please sign in to comment.