Skip to content

Radon crashes on unrelated config option in pyproject.toml #244

@jannismain

Description

@jannismain

When I have a string format in an unrelated section in pyproject.toml, radon crashes with the following message:

Traceback (most recent call last):
  File "/Users/mkj/.local/bin/radon", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/mkj/.local/pipx/venvs/radon/lib/python3.11/site-packages/radon/__init__.py", line 10, in main
    from radon.cli import program, log_error
  File "/Users/mkj/.local/pipx/venvs/radon/lib/python3.11/site-packages/radon/cli/__init__.py", line 90, in <module>
    _cfg = FileConfig()
           ^^^^^^^^^^^^
  File "/Users/mkj/.local/pipx/venvs/radon/lib/python3.11/site-packages/radon/cli/__init__.py", line 45, in __init__
    self.file_cfg = self.file_config()
                    ^^^^^^^^^^^^^^^^^^
  File "/Users/mkj/.local/pipx/venvs/radon/lib/python3.11/site-packages/radon/cli/__init__.py", line 85, in file_config
    config.read_dict(FileConfig.toml_config())
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/configparser.py", line 770, in read_dict
    self.set(section, key, value)
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/configparser.py", line 1220, in set
    super().set(section, option, value)
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/configparser.py", line 910, in set
    value = self._interpolation.before_set(self, section, option,
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/configparser.py", line 403, in before_set
    raise ValueError("invalid interpolation syntax in %r at "
ValueError: invalid interpolation syntax in '%(lineno)d' at position 0

My minimal example config:

[tool.some_tool]
some_option = "%(lineno)d"

I have encountered this when upgrading to radon 6.0.1 while using a custom log_format option in a pytest configuration section.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions