Skip to content

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

Open
brianschubert wants to merge 2 commits intopython:mainfrom
brianschubert:stdlib-logging-basicConfig-mutually-exclusive
Open

Make filename, stream, and handlers parameters of logging.basicConfig mutually-exclusive#15435
brianschubert wants to merge 2 commits intopython:mainfrom
brianschubert:stdlib-logging-basicConfig-mutually-exclusive

Conversation

@brianschubert
Copy link
Collaborator

For reference:

>>> logging.basicConfig(filename="foo.log", handlers=[])
Traceback (most recent call last):
  ...
ValueError: 'stream' or 'filename' should not be specified together with 'handlers'

>>> logging.basicConfig(filename="foo.log", stream=None)
Traceback (most recent call last):
  ...
ValueError: 'stream' and 'filename' should not be specified together

>>> logging.basicConfig(filename="foo.log", filemode="w")
>>> logging.basicConfig(handlers=[], filemode="w")
Traceback (most recent call last):
  ...
ValueError: Unrecognised argument(s): filemode

Source: https://github.com/python/cpython/blob/3.14/Lib/logging/__init__.py#L2005
Docs: https://docs.python.org/3/library/logging.html#logging.basicConfig

@brianschubert
Copy link
Collaborator Author

cc @hamdanal since you looked at this function recently

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

logging.basicConfig(stream=None)
logging.basicConfig(stream=None, handlers=None)
# 'filemode' is inert when 'filename' is not passed, but is accepted if 'handlers=None'.
logging.basicConfig(filemode="w", stream=None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like a case where we could forbid filemode to prevent an error where users pass it, expecting to do something when it doesn't. But I don't have strong feelings either way.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one potential comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants