Skip to content

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

Merged
srittau merged 3 commits intopython:mainfrom
brianschubert:stdlib-logging-basicConfig-mutually-exclusive
Feb 18, 2026
Merged

Make filename, stream, and handlers parameters of logging.basicConfig mutually-exclusive#15435
srittau merged 3 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

This comment has been minimized.

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 Author

@brianschubert brianschubert Feb 18, 2026

Choose a reason for hiding this comment

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

Sounds reasonable. The same is actually true for encoding and errors as well (all three do nothing when filename is not specified), so I think I'll remove all three from the overloads that don't include filename

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.

@github-actions
Copy link
Contributor

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

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.

Thanks!

@srittau srittau merged commit d4a1c39 into python:main Feb 18, 2026
51 checks passed
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

Comments