Skip to content

Commit a07ccf7

Browse files
authored
ArgumentParser: use broader file type (#18354)
This is in anticipation of python/typeshed#13324
1 parent 44bf7e5 commit a07ccf7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mypy/main.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from collections import defaultdict
1111
from gettext import gettext
1212
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
1414

1515
from mypy import build, defaults, state, util
1616
from mypy.config_parser import (
@@ -35,6 +35,11 @@
3535
from mypy.split_namespace import SplitNamespace
3636
from mypy.version import __version__
3737

38+
39+
class _SupportsWrite(Protocol):
40+
def write(self, s: str, /) -> object: ...
41+
42+
3843
orig_stat: Final = os.stat
3944
MEM_PROFILE: Final = False # If True, dump memory profile
4045

@@ -372,17 +377,17 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
372377
# =====================
373378
# Help-printing methods
374379
# =====================
375-
def print_usage(self, file: IO[str] | None = None) -> None:
380+
def print_usage(self, file: _SupportsWrite | None = None) -> None:
376381
if file is None:
377382
file = self.stdout
378383
self._print_message(self.format_usage(), file)
379384

380-
def print_help(self, file: IO[str] | None = None) -> None:
385+
def print_help(self, file: _SupportsWrite | None = None) -> None:
381386
if file is None:
382387
file = self.stdout
383388
self._print_message(self.format_help(), file)
384389

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:
386391
if message:
387392
if file is None:
388393
file = self.stderr

0 commit comments

Comments
 (0)