self.config_args["here"] = here
file_config = ConfigParser(self.config_args)
if self.config_file_name:
- file_config.read([self.config_file_name])
+ compat.read_config_parser(file_config, [self.config_file_name])
else:
file_config.add_section(self.config_ini_section)
return file_config
from __future__ import annotations
+from configparser import ConfigParser
import io
import os
import sys
import typing
from typing import Sequence
+from typing import Union
from sqlalchemy.util import inspect_getfullargspec # noqa
from sqlalchemy.util.compat import inspect_formatargspec # noqa
is_posix = os.name == "posix"
py311 = sys.version_info >= (3, 11)
+py310 = sys.version_info >= (3, 10)
py39 = sys.version_info >= (3, 9)
py38 = sys.version_info >= (3, 8)
elif isinstance(annotation, typing.TypeVar):
return repr(annotation).replace("~", "")
return repr(annotation).replace("~", "")
+
+
+def read_config_parser(
+ file_config: ConfigParser,
+ file_argument: Sequence[Union[str, os.PathLike[str]]],
+) -> list[str]:
+ if py310:
+ return file_config.read(file_argument, encoding="locale")
+ else:
+ return file_config.read(file_argument)
--- /dev/null
+.. change::
+ :tags: bug, commands
+ :tickets: 1273
+
+ Added ``encoding="locale"`` setting to the use of Python's
+ ``ConfigParser.read()``, so that a warning is not generated when using the
+ recently added Python feature ``PYTHONWARNDEFAULTENCODING`` specified in
+ :pep:`597`. The encoding is passed as the ``"locale"`` string under Python
+ 3.10 and greater, which indicates that the system-level locale should be
+ used, as was the case already here. Pull request courtesy Kevin Kirsche.
+