Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

logging.configcfg protocol rejects non-alphanumeric names, contrary to the documentation #103384

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@tomasr8

Description

@tomasr8

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

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp