Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Description
Description
Inlogging.config, when using thecfg protocol, names with spaces or non-alphanumeric characters (e.g.cfg://nested[prop with spaces]) raise aValueError contrary to what is stated in the documentation.
Thedocumentation states that one can use the bracket notation:
The latter form only needs to be used if the key contains spaces or non-alphanumeric characters.
This does not work however:
fromlogging.configimportBaseConfiguratorconfig= {'nested': {'prop':1,'prop with spaces':2}}# Create a simple logging configbc=BaseConfigurator(config)bc.cfg_convert('nested[prop]')# returns 1 (expected)bc.cfg_convert('nested[prop with spaces]')# Raises ValueErrorTraceback (mostrecentcalllast):File"<stdin>",line1,in<module>File"/home/tomas/dev/cpython/Lib/logging/config.py",line433,incfg_convertraiseValueError('Unable to convert 'ValueError:Unabletoconvert'nested[prop with spaces]'at'[prop with spaces]'
ValueError is also raised for any non-alphanumeric sequence:
bc.cfg_convert('nested[!?]')# Raises
The culprit is the regex pattern (BaseConfigurator.INDEX_PATTERN) which is used for matching the bracket contents:^\[\s*(\w+)\s*\]\s*.
This only matches alphanumeric characters. Simply changing this to^\[([^\[\]]*)\]\s* would give us the behavior described in the docs.
Your environment
- CPython versions tested on: 3.12.0a6+
- Operating system and architecture: Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status