powerline / powerline

Powerline is a statusline plugin for vim, and provides statuslines and prompts for several other applications, including zsh, bash, tmux, IPython, Awesome and Qtile.

Home Page:https://powerline.readthedocs.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

powerline-lint raises exception b/c it's using collections.Hashabe

Henry78 opened this issue · comments

Issue

Running powerline-lint raises an exception:

[...]
  File "/usr/lib/python3.10/site-packages/powerline/lint/markedjson/constructor.py", line 19, in f
    return gen_marked_value(func(self, node, *args, **kwargs), node.start_mark)
  File "/usr/lib/python3.10/site-packages/powerline/lint/markedjson/constructor.py", line 125, in construct_mapping
    if not isinstance(key, collections.Hashable):
AttributeError: module 'collections' has no attribute 'Hashable'

Fix

I fixed it by

--- /home/user/constructor.py	2022-04-08 20:58:03.384414806 +0200
+++ /usr/lib/python3.10/site-packages/powerline/lint/markedjson/constructor.py	2022-04-08 20:58:15.154397215 +0200
@@ -122,7 +122,7 @@
 		mapping = {}
 		for key_node, value_node in node.value:
 			key = self.construct_object(key_node, deep=deep)
-			if not isinstance(key, collections.abc.Hashable):
+			if not isinstance(key, collections.Hashable):
 				self.echoerr(
 					'While constructing a mapping', node.start_mark,
 					'found unhashable key', key_node.start_mark

This seems to have changed with Python3.3, see (collections.abc documentation). As I'm a new user of powerline and not experienced with Python, I'm not sure if or how this worked until now. Also, this is afaik the only direct use (not imported) of collections.

Environment

  • Arch
  • python-powerline-2.8.2
  • python-3.10.4

Nice catch, thanks!

If I recall correctly collections.Hashable did work in recent versions of python (i.e. 3.x) as I'm pretty sure powerline-lint worked as intended; most likely collections.Hashable was used for compatibility with python 2.y.

Now, as we do not support python 2 anymore and using collections.Hashable was at best questionable in python 3, I just fixed this.