Repository navigation
TypeError: unhashable type: 'list' when using dulwich 0.24.6 with Python <3.9.2 #1948
Description
Hi!
This may end up being wontfix (given it only affects older Python 3.9 patch versions), but filing for awareness / in case it helps others.
With the release of dulwich 0.24.6 our CI started failing with TypeError: unhashable type: 'list' errors when invoking Poetry with Python 3.9.0.
For example:
https://github.com/heroku/heroku-buildpack-python/actions/runs/18650476440/job/53167114670?pr=1941#step:5:544
I was able to reproduce this outside of Poetry - it affects Python 3.9.0 and 3.9.1 only (and not Python 3.9.2+).
For example:
$ docker run --rm python:3.9.1-slim bash -c 'pip install --disable-pip-version-check dulwich==0.24.6 && python -c "from dulwich import porcelain"'
Collecting dulwich==0.24.6
Downloading dulwich-0.24.6-cp39-cp39-manylinux_2_28_aarch64.whl (1.3 MB)
Collecting urllib3>=2.2.2
Downloading urllib3-2.5.0-py3-none-any.whl (129 kB)
Collecting typing_extensions>=4.0
Downloading typing_extensions-4.15.0-py3-none-any.whl (44 kB)
Installing collected packages: urllib3, typing-extensions, dulwich
Successfully installed dulwich-0.24.6 typing-extensions-4.15.0 urllib3-2.5.0
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/dulwich/porcelain.py", line 126, in <module>
from .bisect import BisectState
File "/usr/local/lib/python3.9/site-packages/dulwich/bisect.py", line 29, in <module>
from dulwich.repo import Repo
File "/usr/local/lib/python3.9/site-packages/dulwich/repo.py", line 66, in <module>
from . import reflog, replace_me
File "/usr/local/lib/python3.9/site-packages/dulwich/reflog.py", line 208, in <module>
reachable_checker: Optional[Callable[[bytes], bool]] = None,
File "/usr/local/lib/python3.9/typing.py", line 262, in inner
return func(*args, **kwds)
File "/usr/local/lib/python3.9/typing.py", line 339, in __getitem__
return self._getitem(self, parameters)
File "/usr/local/lib/python3.9/typing.py", line 463, in Optional
return Union[arg, type(None)]
File "/usr/local/lib/python3.9/typing.py", line 262, in inner
return func(*args, **kwds)
File "/usr/local/lib/python3.9/typing.py", line 339, in __getitem__
return self._getitem(self, parameters)
File "/usr/local/lib/python3.9/typing.py", line 451, in Union
parameters = _remove_dups_flatten(parameters)
File "/usr/local/lib/python3.9/typing.py", line 231, in _remove_dups_flatten
return tuple(_deduplicate(params))
File "/usr/local/lib/python3.9/typing.py", line 205, in _deduplicate
all_params = set(params)
TypeError: unhashable type: 'list'
To resolve the error, one needs to either:
- Downgrade dulwich to 0.24.5 or older
- Or, upgrade Python 3.9.0/3.9.1 to Python 3.9.2 or newer
The typing usage that is tripping up the typing module is on this line:
Line 208 in 1702e77
| reachable_checker: Optional[Callable[[bytes], bool]] = None, |
And was introduced in this PR:
https://github.com/jelmer/dulwich/pull/1941/files#diff-d4672769f4e2861358cbfa19fdf0f71c481575deec25d702a93f96baecf5cf6cR208
Looking at the Python 3.9.2 release notes:
https://docs.python.org/3.9/whatsnew/changelog.html#python-3-9-2-final
...I see this entry:
bpo-42195: The args of the parameterized generics for typing.Callable and collections.abc.Callable are now consistent. The args for collections.abc.Callable are now flattened while typing.Callable’s have not changed. To allow this change, types.GenericAlias can now be subclassed and collections.abc.Callable’s class_getitem will now return a subclass of types.GenericAlias. Tests for typing were also updated to not subclass things like Callable[..., T] as that is not a valid base class. Finally, both types no longer validate their argtypes, in Callable[[argtypes], resulttype] to prepare for PEP 612. Patch by Ken Jin.
It seems like the relevant upstream CPython 3.9 change that resolves this issue, is that in the last sentence? ("both types no longer validate their argtypes") ie:
- Inconsistent __args__ between typing.Callable and collections.abc.Callable python/cpython#86361
- [3.9] bpo-42195: Ensure consistency of Callable's __args__ in collections.abc and typing (GH-23060) python/cpython#23765
Additional context
The reason we have a test for Python 3.9.0, is that our tool (a buildpack) allows end users to pick arbitrary Python versions to install (similar to pyenv or GitHub Actions allowing people to pick their Python version) - and so to ensure backwards compatibility, we not only have tests for each supported Python package manager against the latest patch release of each major Python version (3.9-3.14), but also the oldest available Python version too (ie for Python 3.9 we test both 3.9.24 and 3.9.0). We're due to drop end-user support for Python 3.9 in January 2026.
Activity
edmorley commentedon Oct 21, 2025
So one possible workaround on the dulwich side, might be to:
requires_pythonto be>=3.9.2rather than>=3.9(dulwich/pyproject.toml
Line 26 in 1702e77
Doing this would mean a
pip install dulwichon Python 3.9.0 / 3.9.1 would cause pip to automatically backtrack the dulwich package version back down to 0.24.5, without the need for end users knowing they need to explicitly specifydulwich<0.24.6. (Yanking doesn't delete the old version - anyone who pins explicitly todulwich==0.24.6will still be able to use it.)Would this be something you'd be open to? :-)
Pin Poetry's `dulwich` version
Pin Poetry's `dulwich` version
Pin Poetry's `dulwich` version (#1943)
Pin Poetry's `dulwich` version (#447)
Work around typing module bug in Python 3.9.0/3.9.1
Work around typing module bug in Python 3.9.0/3.9.1
jelmer commentedon Oct 21, 2025
I'm inclined to just convert this type annotation to a string one for now, that should probably address it.
jelmer commentedon Oct 21, 2025
@edmorley any chance you could test #1949 with python 3.9.0? I don't have easy access to Python 3.9.0 anymore unfortunately.
Work around typing module bug in Python 3.9.0/3.9.1
edmorley commentedon Oct 21, 2025
Thank you for the quick reply!
#1949 fixes the error for me, when testing locally using Docker (and the non-slim Python image, which contains Git) and dulwich installed from the PR's branch :-)
jelmer commentedon Oct 21, 2025
Great, thanks for verifying!
Work around typing module bug in Python 3.9.0/3.9.1 (#1949)
Work around typing module bug in Python 3.9.0/3.9.1
Work around typing module bug in Python 3.9.0/3.9.1 (#1949)
Unpin Poetry's `dulwich` version
Unpin Poetry's `dulwich` version
Unpin Poetry's `dulwich` version (#464)
Unpin Poetry's `dulwich` version
Unpin Poetry's `dulwich` version (#1967)
Work around typing module bug in Python 3.9.0/3.9.1
Work around typing module bug in Python 3.9.0/3.9.1 (#1949)