Skip to content

ArgumentParser: use broader file type #18354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading