From d55436ace3cb908e0f7a1f368a2cd8879175947d Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Wed, 18 Mar 2015 08:47:58 +0000 Subject: Issue #23207: Improved kwarg validation. --- Lib/logging/__init__.py | 2 +- Lib/test/test_logging.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 9a8685b..e866b96 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1734,8 +1734,8 @@ def basicConfig(**kwargs): "specified together with 'handlers'") if handlers is None: filename = kwargs.pop("filename", None) + mode = kwargs.pop("filemode", 'a') if filename: - mode = kwargs.pop("filemode", 'a') h = FileHandler(filename, mode) else: stream = kwargs.pop("stream", None) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 54be217..8770e1b 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3589,6 +3589,10 @@ class BasicConfigTest(unittest.TestCase): handlers=handlers) assertRaises(ValueError, logging.basicConfig, stream=stream, handlers=handlers) + # Issue 23207: test for invalid kwargs + assertRaises(ValueError, logging.basicConfig, loglevel=logging.INFO) + # Should pop both filename and filemode even if filename is None + logging.basicConfig(filename=None, filemode='a') def test_handlers(self): handlers = [ -- cgit v0.12