Skip to content

Fix for collections.Callable removal on python >= 3.9#78

Open
greyblue9 wants to merge 1 commit intopyreadline:masterfrom
greyblue9:master
Open

Fix for collections.Callable removal on python >= 3.9#78
greyblue9 wants to merge 1 commit intopyreadline:masterfrom
greyblue9:master

Conversation

@greyblue9
Copy link

@greyblue9 greyblue9 commented Apr 21, 2022

On python 3.9 and later (tested with 3.11 alpha-3), pyreadline's startup hook unfortunately fails due to some once-deprecated names being finally removed in the stdlib. The cause is thatCallable has been removed from the collections module since python 3.9 The location to use is collections.abc. Slight tweak to the code so that it will work for both setups.

Python Version: Python 3.11.0a3 (main, Dec 8 2021, 22:56:33) [MSC v.1929 64 bit (AMD64)] on win32
PyReadline Version: pyreadline-2.1 (from pypi pyreadline-2.1.zip)
Full traceback:

Failed calling sys.__interactivehook__
Traceback (most recent call last):
  File "<frozen site>", line 445, in register_readline
  File "C:\Users\David\AppData\Local\Programs\Python\Python311\Lib\site-packages\readline.py", line 34, in <module>
    rl = Readline()
         ^^^^^^^^^^
  File "C:\Users\David\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
    BaseReadline.__init__(self)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\David\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
    mode.init_editing_mode(None)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\David\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
    self._bind_key('space',       self.self_insert)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\David\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
    if not callable(func):
           ^^^^^^^^^^^^^^
  File "C:\Users\David\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
    return isinstance(x, collections.Callable)
                         ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Callable'

@arunanshub
Copy link

Looks like this project is not in active development.

@greyblue9
Copy link
Author

greyblue9 commented Apr 28, 2022

What are Windows python users doing these days to get functional readline editing? I am genuinely perplexed. Unless most have moved on from the built-in repl. It turns out this fix would be needed all the way back to 3.9 , too (that's when Callable was removed from collections).

(Aside: I would be glad to take over from the maintainer if they're not interested anymore or just don't have time/energy to dedicate towards upkeep. I do find this a very helpful package. 😍)

Looks like this project is not in active development.

Yeah, does look like it. And I believe that a similar package, gnureadline, used to work as well. Sadly, around the time I made this PR it was not possible to install gnureadline, at all. That's why I thought of just patching pyreadline. 😅

Would you consider using a fork, just out of curiosity? 🤔

@greyblue9 greyblue9 changed the title collections.abc.Callable for 3.11 compat Fix for collections.Callable removal on python >= 3.9 Apr 28, 2022
@arunanshub
Copy link

Consider using pyreadline3. It's a maintained version of pyreadline. It's sad that the Devs haven't updated their dependencies.

This is how I specified dependencies for Windows:

pyreadline3 = {version = "^3.4.1", markers = "sys_platform == 'win32'"}

@greyblue9
Copy link
Author

This is how I specified dependencies for Windows:

pyreadline3 = {version = "^3.4.1", markers = "sys_platform == 'win32'"}

Thanks for the tip! I didn't know about this one.

@liudonghua123
Copy link

pip install pyreadline3 works for me!

Details
Liu.D.H  windows-python-installer  git(3.12)   14ms  17:47 > milvus_cli.exe --help
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Scripts\milvus_cli.exe\__main__.py", line 4, in <module>
    from milvus_cli.scripts.milvus_cli import runCliPrompt
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\milvus_cli\scripts\milvus_cli.py", line 1, in <module>
    from .connection_cli import *
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\milvus_cli\scripts\connection_cli.py", line 2, in <module>
    from .helper_cli import show, getList
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\milvus_cli\scripts\helper_cli.py", line 10, in <module>
    from utils import WELCOME_MSG, EXIT_MSG, Completer, getPackageVersion
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\milvus_cli\utils.py", line 1, in <module>
    import readline
ModuleNotFoundError: No module named 'readline'

Liu.D.H  windows-python-installer  git(3.12)   4.315s  17:48 > pip install readline
Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
Collecting readline
  Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/f4/01/2cf081af8d880b44939a5f1b446551a7f8d59eae414277fd0c303757ff1b/readline-6.2.4.1.tar.gz (2.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 1.4 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      error: this module is not meant to work on Windows
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Liu.D.H  windows-python-installer  git(3.12)   15.534s  17:49 >
Liu.D.H  windows-python-installer  git(3.12)   3.171s  17:50 > pip install pyreadline
Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
Collecting pyreadline
  Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/bc/7c/d724ef1ec3ab2125f38a1d53285745445ec4a8f19b9bb0761b4064316679/pyreadline-2.1.zip (109 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyreadline
  Building wheel for pyreadline (pyproject.toml) ... done
  Created wheel for pyreadline: filename=pyreadline-2.1-py3-none-any.whl size=93920 sha256=a1e081c7c05e459883a6d182616a4770720ef84c38f6f2640a4474466c7b5618
  Stored in directory: c:\users\liu.d.h\appdata\local\pip\cache\wheels\f4\53\a0\25d711c8f6c472b3de5d533d4bb2c81554928d09afab8005e4
Successfully built pyreadline
Installing collected packages: pyreadline
Successfully installed pyreadline-2.1

Liu.D.H  windows-python-installer  git(3.12)   13.789s  17:51 > milvus_cli.exe --help
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Scripts\milvus_cli.exe\__main__.py", line 4, in <module>
    from milvus_cli.scripts.milvus_cli import runCliPrompt
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\milvus_cli\scripts\milvus_cli.py", line 1, in <module>
    from .connection_cli import *
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\milvus_cli\scripts\connection_cli.py", line 2, in <module>
    from .helper_cli import show, getList
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\milvus_cli\scripts\helper_cli.py", line 10, in <module>
    from utils import WELCOME_MSG, EXIT_MSG, Completer, getPackageVersion
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\milvus_cli\utils.py", line 1, in <module>
    import readline
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\readline.py", line 34, in <module>
    rl = Readline()
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
    BaseReadline.__init__(self)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
    mode.init_editing_mode(None)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
    self._bind_key('space',       self.self_insert)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
    if not callable(func):
           ~~~~~~~~^^^^^^
  File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python313\Lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
    return isinstance(x, collections.Callable)
                         ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Callable'

Liu.D.H  windows-python-installer  git(3.12)   1.428s  17:51 > pip install pyreadline3
Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
Collecting pyreadline3
ff9ab5cdbac86e1/pyreadline3-3.5.4-py3-none-any.whl (83 kB)
Installing collected packages: pyreadline3
Successfully installed pyreadline3-3.5.4

Liu.D.H  windows-python-installer  git(3.12)   4.072s  17:52 > milvus_cli.exe --help



  __  __ _ _                    ____ _     ___
 |  \/  (_) |_   ___   _ ___   / ___| |   |_ _|
 | |\/| | | \ \ / / | | / __| | |   | |    | |
 | |  | | | |\ V /| |_| \__ \ | |___| |___ | |
 |_|  |_|_|_| \_/  \__,_|___/  \____|_____|___|

Milvus cli version: 1.0.1
Pymilvus version: 2.5.4

Learn more: https://github.com/zilliztech/milvus_cli.


milvus_cli > exit


Thanks for using.
We hope your feedback: https://github.com/zilliztech/milvus_cli/issues/new.



Liu.D.H  windows-python-installer  git(3.12)   5.123s  17:52 >

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.

4 participants