Skip to content

fix(asyncio): make RunningCommand hashable for asyncio.gather (#800) - #802

Open
ansh-rohilla wants to merge 1 commit into
amoffat:developfrom
ansh-rohilla:fix/running-command-hashable
Open

ansh-rohilla wants to merge 1 commit into
amoffat:developfrom
ansh-rohilla:fix/running-command-hashable

Conversation

@ansh-rohilla

Copy link
Copy Markdown

Summary

RunningCommand defines __eq__ (return id(self) == id(other)), but did not define __hash__. In Python 3, overriding __eq__ without explicitly defining __hash__ implicitly sets __hash__ = None, making instances unhashable.

Because RunningCommand implements __await__, instances are commonly passed to asyncio.gather(*commands). However, asyncio.gather uses an internal dictionary lookup (arg not in arg_to_fut), which raised:

TypeError: unhashable type: 'RunningCommand'

Following the Python data model convention for classes with identity equality, this sets __hash__ = object.__hash__ on RunningCommand.

Changes

  • Added __hash__ = object.__hash__ to RunningCommand in src/sh/__init__.py.
  • Added regression test test_async_gather in tests/sh_test.py verifying hashability, set/dict lookups, and concurrent completion with asyncio.gather.

Closes #800

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio.gather fails because RunningCommand is not hashable

1 participant