deshaw / pyflyby

A set of productivity tools for Python
https://deshaw.github.io/pyflyby/
Other
353 stars 52 forks source link

`pyflyby.install_in_ipython_config_file` is broken in Python 3 #234

Closed peytondmurray closed 1 year ago

peytondmurray commented 1 year ago

When running py pyflyby.install_in_ipython_config_file, pyflyby breaks. getargspec is deprecated in Python 3, which is the reason this fails. Currently this is breaking a feature of the jupyterlab-pyflyby extension.

$ py pyflyby.install_in_ipython_config_file
[PYFLYBY] import pyflyby
Traceback (most recent call last):
  File "/home/pdmurray/.pyenv/versions/pj/bin/py", line 8, in <module>
    sys.exit(py_main())
             ^^^^^^^^^
  File "/home/pdmurray/.pyenv/versions/3.11.2/envs/pj/lib/python3.11/site-packages/pyflyby/_py.py", line 2052, in py_main
    _PyMain(args).run()
  File "/home/pdmurray/.pyenv/versions/3.11.2/envs/pj/lib/python3.11/site-packages/pyflyby/_py.py", line 1787, in run
    self._run_action()
  File "/home/pdmurray/.pyenv/versions/3.11.2/envs/pj/lib/python3.11/site-packages/pyflyby/_py.py", line 2022, in _run_action
    self.heuristic_cmd(cmd, args, function_name=arg0)
  File "/home/pdmurray/.pyenv/versions/3.11.2/envs/pj/lib/python3.11/site-packages/pyflyby/_py.py", line 1549, in heuristic_cmd
    result = auto_apply(function, cmd_args, self.namespace,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pdmurray/.pyenv/versions/3.11.2/envs/pj/lib/python3.11/site-packages/pyflyby/_py.py", line 986, in auto_apply
    argspec = _get_argspec(function.value)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pdmurray/.pyenv/versions/3.11.2/envs/pj/lib/python3.11/site-packages/pyflyby/_py.py", line 383, in _get_argspec
    from inspect import getargspec, ArgSpec
ImportError: cannot import name 'getargspec' from 'inspect' (/home/pdmurray/.pyenv/versions/3.11.2/lib/python3.11/inspect.py)
aktech commented 1 year ago

I can reproduce this in Python 3.11. Although it works until Python 3.10 (See deprecated inspect.getargspec(func)) and pyflyby is supported upto 3.10 at the moment, so this is more of a feature request to support 3.11. What do you think?

peytondmurray commented 1 year ago

I'll defer to you on how you want to classify this issue. IMO at the very least if a version is here it should be tested/supported, and if a version is deprecated it should be totally dropped from all code. Personally I'd prefer if projects followed NEP29 on this, which is a more strict deprecation schedule.

aktech commented 1 year ago

This is fixed (Tested on master) as part of this https://github.com/deshaw/pyflyby/pull/227 Let me know if this doesn't works.