Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wshanks opened this issue Nov 29, 2023 · 4 comments · Fixed by #626
Closed

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

wshanks opened this issue Nov 29, 2023 · 4 comments · Fixed by #626
Labels

Comments

@wshanks
Copy link
Contributor

wshanks commented Nov 29, 2023

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

@wshanks wshanks added the Bug label Nov 29, 2023
@inducer
Copy link
Owner

inducer commented Dec 5, 2023

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
Copy link
Owner

inducer commented Dec 5, 2023

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

@wshanks
Copy link
Contributor Author

wshanks commented Dec 27, 2023

Sure, I will give it a shot!

@wshanks
Copy link
Contributor Author

wshanks commented Dec 30, 2023

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants