pywinusb icon indicating copy to clipboard operation
pywinusb copied to clipboard

core.py collections callable error

Open ThommyL34 opened this issue 1 year ago • 0 comments

Hi,

I tried the example show_hids.py from this repo and this error occurs:

..Project\venv\Lib\site-packages\pywinusb\hid\core.py", line 1567, in inspect if isinstance(value, collections.Callable): ^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'collections' has no attribute 'Callable'

Specs:

  • pywinusb 0.4.2
  • Win11
  • Python Version: 3.11.4
  • IDE: PyCharm 2023.2.3 Com.Ed.
  • Script runs with venv (by default from PyCharm)

Note: Googl`d error background: This error occurs in other contexts, too. Mostly when older packages are being used in combination with modern python versions. So I think i found a fix and I thought about sharing it if you want to include it in a future version.

The Fix:

File: core.py Action:

  1. Replace line 14 from import collections to import _collections_abc
  2. Replace line 1567 from if isinstance(value, collection.Callable): to if isinstance(value, _collections_abc.Callable).

New behavior:

No error message and a long print of HID information.

ThommyL34 avatar Nov 02 '23 22:11 ThommyL34