Skip to content

Commit e90fe8b

Browse files
committed
Disallow passing filemode, encoding, or errors without filename
1 parent 1cdd578 commit e90fe8b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

stdlib/@tests/test_cases/check_logging.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ def record_factory(*args: Any, **kwargs: Any) -> logging.LogRecord:
4242
logging.basicConfig(filename="foo.log", filemode="w", handlers=None)
4343
logging.basicConfig(stream=None)
4444
logging.basicConfig(stream=None, handlers=None)
45-
# 'filemode' is inert when 'filename' is not passed, but is accepted if 'handlers=None'.
46-
logging.basicConfig(filemode="w", stream=None)
4745
# dubious but accepted, has same meaning as 'stream=None'.
4846
logging.basicConfig(filename=None)
47+
# These are technically accepted at runtime, but are forbidden in the stubs to help
48+
# prevent user mistakes. Passing 'filemode' / 'encoding' / 'errors' does nothing
49+
# if 'filename' is not specified.
50+
logging.basicConfig(stream=None, filemode="w") # type: ignore
51+
logging.basicConfig(stream=None, encoding="utf-8") # type: ignore
52+
logging.basicConfig(stream=None, errors="strict") # type: ignore
53+
logging.basicConfig(handlers=[], encoding="utf-8") # type: ignore
54+
logging.basicConfig(handlers=[], errors="strict") # type: ignore

stdlib/logging/__init__.pyi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,6 @@ def basicConfig(
585585
level: _Level | None = None,
586586
handlers: Iterable[Handler],
587587
force: bool | None = False,
588-
encoding: str | None = None,
589-
errors: str | None = "backslashreplace",
590588
) -> None: ...
591589
@overload # handlers is None, filename is passed (but possibly None)
592590
def basicConfig(
@@ -605,16 +603,13 @@ def basicConfig(
605603
@overload # handlers is None, filename is not passed
606604
def basicConfig(
607605
*,
608-
filemode: str = "a",
609606
format: str = ..., # default value depends on the value of `style`
610607
datefmt: str | None = None,
611608
style: _FormatStyle = "%",
612609
level: _Level | None = None,
613610
stream: SupportsWrite[str] | None = None,
614611
handlers: None = None,
615612
force: bool | None = False,
616-
encoding: str | None = None,
617-
errors: str | None = "backslashreplace",
618613
) -> None: ...
619614
def shutdown(handlerList: Sequence[Any] = ...) -> None: ... # handlerList is undocumented
620615
def setLoggerClass(klass: type[Logger]) -> None: ...

0 commit comments

Comments
 (0)