inducer / pudb

Full-screen console debugger for Python
https://documen.tician.de/pudb/
Other
2.94k stars 226 forks source link

telnetlib (used for remote debugger) is deprecated in Python 3.12 #621

Closed wshanks closed 8 months ago

wshanks commented 9 months ago

Describe the bug Python 3.12 has deprecated telnetlib. It is going to be removed in 3.13.

To Reproduce Use pudb.remote.set_trace() in code and then connect to the telnet session.

Expected behavior No deprecation warning

Screenshots This is the terminal output:

      File "/tmp/lib/python3.12/site-packages/pudb/remote.py", line 237, in set_trace                                                 
    return debugger(                                                           
           ^^^^^^^^^                                                           

      File "/tmp/lib/python3.12/site-packages/pudb/remote.py", line 223, in debugger                                                                                                                                                                                                                 
    rdb = _current[0] = RemoteDebugger(                                        
                        ^^^^^^^^^^^^^^^                                                                                                                        

      File "/tmp/lib/python3.12/site-packages/pudb/remote.py", line 142, in __init__                                                  
    import telnetlib as tn                                                     

      File "/tmp/lib/python3.12/telnetlib.py", line 42, in <module>                                                                   
    warnings._deprecated(__name__, remove=(3, 13))                             

      File "/tmp/lib/python3.12/warnings.py", line 529, in _deprecated                                                                
    warn(msg, DeprecationWarning, stacklevel=3)                                                                                                                

    DeprecationWarning: 'telnetlib' is deprecated and slated for removal in Python 3.13

Additional context It looks like the code only uses telnetlib for the constants, not for any functions, so it should be easy to vendor them in. At first, I thought it would be necessary to migrate to something like telnetlib3.

There is an additional deprecation warnging after the telnet one:

      File "/tmp/lib/python3.12/site-packages/pudb/remote.py", line 237, in set_trace
    return debugger(
           ^^^^^^^^^

      File "/tmp/lib/python3.12/site-packages/pudb/remote.py", line 223, in debugger
    rdb = _current[0] = RemoteDebugger(
                        ^^^^^^^^^^^^^^^

      File "/tmp/lib/python3.12/site-packages/pudb/remote.py", line 152, in __init__
    Debugger.__init__(

      File "/tmp/lib/python3.12/site-packages/pudb/debugger.py", line 209, in __init__
    for bpoint_descr in load_breakpoints():
                        ^^^^^^^^^^^^^^^^^^

      File "/tmp/lib/python3.12/site-packages/pudb/settings.py", line 595, in load_breakpoints
    return parse_breakpoints(lines)
           ^^^^^^^^^^^^^^^^^^^^^^^^

      File "/tmp/lib/python3.12/site-packages/pudb/settings.py", line 557, in parse_breakpoints
    if get_breakpoint_invalid_reason(filename, lineno) is None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "/tmp/lib/python3.12/site-packages/pudb/lowlevel.py", line 144, in get_breakpoint_invalid_reason
    executable_lines = get_executable_lines_for_file(filename)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "/tmp/lib/python3.12/site-packages/pudb/lowlevel.py", line 133, in get_executable_lines_for_file
    return get_executable_lines_for_codes_recursive(codes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "/tmp/lib/python3.12/site-packages/pudb/lowlevel.py", line 119, in get_executable_lines_for_codes_recursive
    execable_lines |= set(generate_executable_lines_for_code(code))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      File "/tmp/lib/python3.12/site-packages/pudb/lowlevel.py", line 101, in generate_executable_lines_for_code
    for line_incr in code.co_lnotab[1::2]:
                     ^^^^^^^^^^^^^^

    DeprecationWarning: co_lnotab is deprecated, use co_lines instead.

It looks like co_lines was added in 3.10, so to support older versions of Python some conditional would need to be used: https://docs.python.org/3/whatsnew/3.10.html#pep-626-precise-line-numbers-for-debugging-and-other-tools

Versions Python 3.12, pudb 2023.1

inducer commented 9 months ago

Thanks for looking into relevant deprecation warnings! #623 should take care of the co_lines thing (that was refreshingly straightforward, compared to the half-documented old scheme). As for the constants from telnetlib, I agree with you that we should simply copy them over and call it a day.

inducer commented 9 months ago

Forgot to ask: would you mind creating a PR for the telnetlib changes?

wshanks commented 8 months ago

Sure, I will give it a shot!

wshanks commented 8 months ago

Thanks for getting fixes for these warnings merged in quickly @inducer! Some projects I work on convert all DeprecationWarnings to exceptions in their test configurations, so it was a little inconvenient that pudb.remote.set_trace would crash when trying to debug tests (though it is not that hard to edit the test configuration to work around it).