Skip to content

Commit 7333e1b

Browse files
simply use default arguments for stdout and stderr
Unless this runs me into the famous Python default argument folly, which doesn't seem likely to me, then this should be a better way to do it. (What, do we change sys.stdout during the course of the program? Guess CI will let me find out...) On another note, sys.stdout and sys.strerr can themselves technically be None, and typeshed gives them MaybeNone to pay homage to this — I would like to actually handle this correctly in the mypy code here, but, what are you going to do, write a message to stderr about it? Guess we'll just roll on.
1 parent 660d911 commit 7333e1b

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

mypy/build.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ def build(
147147
alt_lib_path: str | None = None,
148148
flush_errors: Callable[[str | None, list[str], bool], None] | None = None,
149149
fscache: FileSystemCache | None = None,
150-
stdout: TextIO | None = None,
151-
stderr: TextIO | None = None,
150+
stdout: TextIO = sys.stdout,
151+
stderr: TextIO = sys.stderr,
152152
extra_plugins: Sequence[Plugin] | None = None,
153153
) -> BuildResult:
154154
"""Analyze a program.
@@ -183,8 +183,6 @@ def default_flush_errors(
183183
messages.extend(new_messages)
184184

185185
flush_errors = flush_errors or default_flush_errors
186-
stdout = stdout or sys.stdout
187-
stderr = stderr or sys.stderr
188186
extra_plugins = extra_plugins or []
189187

190188
try:

mypy/config_parser.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,15 @@ def parse_config_file(
314314
options: Options,
315315
set_strict_flags: Callable[[], None],
316316
filename: str | None,
317-
stdout: TextIO | None = None,
318-
stderr: TextIO | None = None,
317+
stdout: TextIO = sys.stdout,
318+
stderr: TextIO = sys.stderr,
319319
) -> None:
320320
"""Parse a config file into an Options object.
321321
322322
Errors are written to stderr but are not fatal.
323323
324324
If filename is None, fall back to default config files.
325325
"""
326-
stdout = stdout or sys.stdout
327-
stderr = stderr or sys.stderr
328326

329327
ret = (
330328
_parse_individual_file(filename, stderr)

mypy/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,8 @@ def add_invertible_flag(
13371337

13381338
def process_options(
13391339
args: list[str],
1340-
stdout: TextIO | None = None,
1341-
stderr: TextIO | None = None,
1340+
stdout: TextIO = sys.stdout,
1341+
stderr: TextIO = sys.stderr,
13421342
require_targets: bool = True,
13431343
server_options: bool = False,
13441344
fscache: FileSystemCache | None = None,
@@ -1352,8 +1352,6 @@ def process_options(
13521352
13531353
Returns a tuple of: a list of source files, an Options collected from flags.
13541354
"""
1355-
stdout = stdout if stdout is not None else sys.stdout
1356-
stderr = stderr if stderr is not None else sys.stderr
13571355

13581356
parser, _, strict_flag_assignments = define_options(
13591357
program, header, stdout, stderr, server_options

0 commit comments

Comments
 (0)