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
Add a context manager to telnetlib.Telnet #69671
Comments
telnetlib.Telnet could have a context manager to call close() automatically. I can provide a patch if the idea is approved, although I have never contributed to Python. |
This seems like a reasonable request to me. See https://docs.python.org/devguide/ to learn how to contribute to Python. |
Here is a small patch |
Maybe, modify the documentation or improve the current examples. |
This probably needs test |
totally agree, I will work on this issue tomorrow |
I was actually writing a patch with a test, but since Stéphane beat me to it, I'll let him do the job :) |
New version of the patch, I have modified the 'test' function. In this function, I use the with statement with the __enter__ and __exit__. |
That's fine as a code change, but that's not the kind of test I meant. There is a Lib/test/test_ftplib.py and it basically needs test_with_statement added to one or few test cases. Have a look at how the similar functions implemented in Lib/test/. |
Ok i will submit an other patch for the tests and the documentation
|
Should I develop a mock telnet server for the unittest ? |
The existing tests seem to have at least some infrastructure that would apply here, so figuring out how to use/extend that is better than writing new code, I'd say. |
Need review for this new patch.
|
I applied the recommendation of SilentGhost for this issue. Need review Thank you |
New changeset 277824f2d133 by R David Murray in branch 'default': |
Thanks, Stéphane. I adjusted the docs...we don't seem to be very consistent about how we document addition of content manager support, so I picked what I liked best. Also, FYI it is generally best (at this point in time) to not include the NEWS item, but enhancements should inlcude a what's new entry (I added one). |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: