Make filename, stream, and handlers parameters of logging.basicConfig mutually-exclusive (#15435)

This commit is contained in:
Brian Schubert
2026-02-18 03:49:35 -05:00
committed by GitHub
parent 2b2a93d632
commit d4a1c39d5c
2 changed files with 48 additions and 3 deletions
+24
View File
@@ -28,3 +28,27 @@ logging.handlers.QueueHandler(multiprocessing.Queue())
logging.handlers.QueueListener(queue.Queue())
logging.handlers.QueueListener(queue.SimpleQueue())
logging.handlers.QueueListener(multiprocessing.Queue())
# These all raise at runtime.
logging.basicConfig(filename="foo.log", handlers=[]) # type: ignore
logging.basicConfig(filemode="w", handlers=[]) # type: ignore
logging.basicConfig(stream=None, handlers=[]) # type: ignore
logging.basicConfig(filename="foo.log", stream=None) # type: ignore
logging.basicConfig(filename=None, stream=None) # type: ignore
# These are ok.
logging.basicConfig()
logging.basicConfig(handlers=[])
logging.basicConfig(filename="foo.log", filemode="w")
logging.basicConfig(filename="foo.log", filemode="w", handlers=None)
logging.basicConfig(stream=None)
logging.basicConfig(stream=None, handlers=None)
# dubious but accepted, has same meaning as 'stream=None'.
logging.basicConfig(filename=None)
# These are technically accepted at runtime, but are forbidden in the stubs to help
# prevent user mistakes. Passing 'filemode' / 'encoding' / 'errors' does nothing
# if 'filename' is not specified.
logging.basicConfig(stream=None, filemode="w") # type: ignore
logging.basicConfig(stream=None, encoding="utf-8") # type: ignore
logging.basicConfig(stream=None, errors="strict") # type: ignore
logging.basicConfig(handlers=[], encoding="utf-8") # type: ignore
logging.basicConfig(handlers=[], errors="strict") # type: ignore