Skip to content

Commit 9c92f22

Browse files
codexByron
authored andcommitted
Fix mypy section-name validation type
The Python package workflow failed in the Ubuntu Python 3.14 job while running mypy. The error reported that GitConfigParser.add_section() may receive configparser's _SectionName type, which is `str | _UNNAMED_SECTION`, but _assure_config_name_safe() accepted only `str`. Keep the runtime validation unchanged for normal string section and option names, but type the guard for configparser section names and only apply the unsafe-character regex to strings. This preserves compatibility with configparser's section-name type while still rejecting CR, LF, and NUL in real names. Validation: - uv run --with gitdb --with mypy --with pytest --with pytest-cov --with ddt --with pytest-mock --with pytest-instafail --with pytest-sugar --with pre-commit mypy --python-version=3.14 - uv run --with gitdb --with pytest --with pytest-cov --with ddt --with pytest-mock --with pytest-instafail --with pytest-sugar python -m pytest test/test_config.py::TestBase::test_set_value_rejects_unsafe_section_and_option_names --no-cov - uv run --with ruff ruff check git/config.py
1 parent e226e42 commit 9c92f22

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

git/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,8 @@ def _value_to_string_safe(self, value: Union[str, bytes, int, float, bool]) -> s
892892
raise ValueError("Git config values must not contain CR, LF, or NUL")
893893
return value_str
894894

895-
def _assure_config_name_safe(self, name: str, label: str) -> None:
896-
if UNSAFE_CONFIG_NAME_RE.search(name):
895+
def _assure_config_name_safe(self, name: "cp._SectionName", label: str) -> None:
896+
if isinstance(name, str) and UNSAFE_CONFIG_NAME_RE.search(name):
897897
raise ValueError("Git config %s names must not contain CR, LF, or NUL" % label)
898898

899899
@needs_values

0 commit comments

Comments
 (0)