Repository: hylang/hy

Issue:
Python 3.10 on Windows fails: AttributeError: module 'collections' has no attribute 'Callable'
Thanks to https://github.com/pyreadline/pyreadline/issues/65, Hy on Python 3.10 on Windows no longer starts, and a backtrace similar to the following is the result:

```console
Traceback (most recent call last):
  File "c:\python\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python\Scripts\hy.exe\__main__.py", line 4, in <module>
  File "c:\python\lib\site-packages\hy\cmdline.py", line 37, in <module>
    from hy.completer import completion, Completer
  File "c:\python\lib\site-packages\hy\completer.py", line 18, in <module>
    import readline
  File "c:\python\lib\site-packages\readline.py", line 34, in <module>
    rl = Readline()
  File "c:\python\lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
    BaseReadline.__init__(self)
  File "c:\python\lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
    mode.init_editing_mode(None)
  File "c:\python\lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
    self._bind_key('space',       self.self_insert)
  File "c:\python\lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
    if not callable(func):
  File "c:\python\lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
    return isinstance(x, collections.Callable)
AttributeError: module 'collections' has no attribute 'Callable'
```

Unfortunately from that bug (and the repository in general), it would appear that `pyreadline` is no longer actively maintained (last update of any kind was in 2015), so for Hy to continue to support Windows on future Python versions will require some amount of workaround (a fork of `pyreadline`, dropping readline support on Windows, etc).

I'm not sure if there's a way to specify that Python 3.10+ and Windows are simply mutually incompatible, but that would be the "simplest" workaround if there's a clean way to specify that. :see_no_evil:


Discussion:
> I'm not sure if there's a way to specify that Python 3.10+ and Windows are simply mutually incompatible

We don't really officially support operating systems other than Linux, because we only test on Linux (https://github.com/hylang/hy/issues/2025#issuecomment-809590718).
If you want to fix this, the easiest way is just to not use Readline in the REPL on Windows.

Resolving patch:
diff --git a/hy/completer.py b/hy/completer.py
--- a/hy/completer.py
+++ b/hy/completer.py
@@ -16,13 +16,14 @@
 
 try:
     import readline
-except ImportError:
-    try:
-        import pyreadline.rlmain
-        import pyreadline.unicode_helper  # NOQA
-        import readline
-    except ImportError:
+except AttributeError as e:
+    # https://github.com/pyreadline/pyreadline/issues/65
+    if "module 'collections' has no attribute 'Callable'" in str(e):
         docomplete = False
+    else:
+        raise
+except ImportError:
+    docomplete = False
 
 if docomplete:
     if sys.platform == 'darwin' and 'libedit' in readline.__doc__:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -69,7 +69,6 @@ def run(self):
         'funcparserlib>=0.3.6',
         'colorama',
         'astor>=0.8 ; python_version < "3.9"',
-        'pyreadline>=2.1 ; os_name == "nt"',
     ],
     cmdclass=dict(install=Install),
     entry_points={


Test patch: