bpo-41906: Accept built filters in dictConfig (GH-30756)

When configuring the logging stack, accept already built filters (or
just callables) in the filters array of loggers and handlers.
This facilitates passing quick callables as filters.

Automerge-Triggered-By: GH:vsajip
This commit is contained in:
Mario Corchero 2022-01-24 13:39:50 +01:00 committed by GitHub
parent 58f3d98098
commit d7c6863979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 1 deletions

View file

@ -694,7 +694,11 @@ class DictConfigurator(BaseConfigurator):
"""Add filters to a filterer from a list of names."""
for f in filters:
try:
filterer.addFilter(self.config['filters'][f])
if callable(f) or callable(getattr(f, 'filter', None)):
filter_ = f
else:
filter_ = self.config['filters'][f]
filterer.addFilter(filter_)
except Exception as e:
raise ValueError('Unable to add filter %r' % f) from e