Skip to content

Commit

Permalink
Read config file without interpolation (codespell-project#2545)
Browse files Browse the repository at this point in the history
Some config files use interpolation, some do not:
https://docs.python.org/3/library/configparser.html#interpolation-of-values

Config files might contain occurrences of `%` that should not be
interpolated. When attempting to interpolate them, `ConfigParser`
crashes with:
	ValueError: invalid interpolation syntax

Therefore, we decide to disable interpolation, to avoid crashes.
We do not expect interpolation in the `[codespell]` section, so
it is not a problem in practice.

Alternatively, we could read with interpolation, and in the case of
a ValueError exception, retry without interpolation. However, since
we do not expect interpolation in the `[codespell]` section, I believe
the current solution is simpler, faster, to the point.
  • Loading branch information
DimitriPapadopoulos authored Oct 31, 2022
1 parent 2461abc commit 71907e2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def parse_options(args):
cfg_files = ['setup.cfg', '.codespellrc']
if options.config:
cfg_files.append(options.config)
config = configparser.ConfigParser()
config = configparser.ConfigParser(interpolation=None)

# Read toml before other config files.
toml_files_errors = list()
Expand Down

0 comments on commit 71907e2

Please sign in to comment.