aosabook/500lines · error · ValueError
arguments to project tasks must be immutable and hashable, n
Error message
arguments to project tasks must be immutable and hashable, not the {} What it means
Error "arguments to project tasks must be immutable and hashable, not the {}" thrown in aosabook/500lines.
Source
Thrown at contingent/code/contingent/projectlib.py:203
return function.__name__, args
class Task(namedtuple('Task', ('task_function', 'args'))):
"""Turn a call to a function into a task 2-tuple.
Given a task function and an argument list, returns a task 2-tuple
that encapsulates the call as a single object. `Project` uses these
task objects for consequence tracking and caching.
Raises `ValueError` if `args` is not hashable.
"""
__slots__ = ()
def __new__(cls, task_function, args):
try:
hash(args)
except TypeError as e:
raise ValueError('arguments to project tasks must be immutable'
' and hashable, not the {}'.format(e))
return super().__new__(cls, task_function, args)
def __repr__(self):
"Produce a “syntactic,” source-like representation of the task."
return '{}({})'.format(self.task_function.__name__,
', '.join(repr(arg) for arg in self.args))
View on GitHub (pinned to fba689d101)
Solutions
- Pass only immutable, hashable argument types (str, int, tuple, frozenset) to project task functions.
- Convert mutable arguments like lists or dicts to tuples/frozensets before creating the task.
- Do not pass objects whose __hash__ changes over time, since tasks are cached by hash.
Example fix
task(project.read_files, (tuple(filenames),)) # tuple(...) instead of the mutable list
When it happens
Trigger: Thrown at contingent/code/contingent/projectlib.py:203 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of aosabook/500lines@fba689d101 (2026-08-13).
Data as JSON: /api/errors/5cca64d9d3bc73c5.
Report an issue: GitHub.