Skip to content

TypeError and AttributeError when using Config objects in sensible ways #1466

Description

@beamerblvd

Constructing a Config with a PathLike results in a TypeError, but this is unnecessary, because the underlying utilities supporting the constructor already support PathLike.

>>> pygit2.Config(pathlib.Path("/Users/nicholas/.gitconfig"))
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    pygit2.Config(pathlib.Path("/Users/nicholas/.gitconfig"))
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nicholas/Development/OSS/libgit2/pygit2/.venv/lib/python3.14/site-packages/pygit2/config.py", line 93, in __init__
    path_bytes = str_to_bytes(path, 'path')
  File "/Users/nicholas/Development/OSS/libgit2/pygit2/.venv/lib/python3.14/site-packages/pygit2/config.py", line 48, in str_to_bytes
    raise TypeError(f'{name} must be a string')
TypeError: path must be a string

Additionally, calling Config.snapshot() on any config object other than one obtained from BaseRepository.config() results in an AttributeError. This includes the system config, the global config, the XDB config, and any other file-based configs:

>>> c = pygit2.Config.get_global_config().snapshot()
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    c = pygit2.Config.get_global_config().snapshot()
  File "/Users/nicholas/Development/OSS/libgit2/pygit2/.venv/lib/python3.14/site-packages/pygit2/config.py", line 270, in snapshot
    return Config.from_c(self._repo, ccfg[0])
                         ^^^^^^^^^^
AttributeError: 'Config' object has no attribute '_repo'

I have a pull request incoming to fix both of these.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions