This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: show addresses in socket.__repr__
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: giampaolo.rodola Nosy List: giampaolo.rodola, neologix, pitrou, python-dev, vstinner, zach.ware
Priority: normal Keywords: patch

Created on 2013-04-09 13:16 by giampaolo.rodola, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
socket-repr.patch giampaolo.rodola, 2013-04-09 13:16 review
socket-repr2.patch giampaolo.rodola, 2013-04-10 01:34 adds tests; use try/except also for getpeername() review
Messages (7)
msg186400 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2013-04-09 13:16
This is useful, for example, when running tests as "python3 -Wa" and you bump into:

ResourceWarning: unclosed <socket object, fd=8, family=2, type=2, proto=0>

With this we'd get:

<socket.socket fd=8, family=2, type=2, proto=0, laddr=('', 37537), raddr=('', 80)>

If desirable, I will add some tests.
msg186440 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-04-09 16:34
This sounds ok to me. It will indeed make things clearer in tests.
msg186452 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2013-04-09 21:40
+1 from me.
Any info that can help debugging is a good thing (calling getsockname() on an non-connected socket will raise an error that will get cacthed, but there's not much we can do about it).
msg186453 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-04-09 21:47
+1 for the idea, +1 for the need of tests.

About the patch: you may use a try/except for getsockname(), and another for getpeername().
msg186495 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-10 13:50
New changeset 1410b7790de6 by Giampaolo Rodola' in branch 'default':
Fix issue #17675: make socket repr() provide local and remote addresses (if any).
msg186595 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2013-04-11 21:05
The new tests fail on Windows, see for example

It can be fixed on Windows by moving the `s.bind(('', 0))` line above the `self.assertIn('laddr', repr(s))` line, though since the test is currently passing on the Unix buildbots, I don't know if the change would break them.
msg186651 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-12 16:28
New changeset e68bd20b5434 by Giampaolo Rodola' in branch 'default':
attempt to fix bb failure as per
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 61875
2013-04-12 16:28:29python-devsetmessages: + msg186651
2013-04-11 21:05:24zach.waresetnosy: + zach.ware
messages: + msg186595
2013-04-10 13:50:57giampaolo.rodolasetstatus: open -> closed
assignee: giampaolo.rodola
type: enhancement
resolution: fixed
stage: resolved
2013-04-10 13:50:04python-devsetnosy: + python-dev
messages: + msg186495
2013-04-10 01:34:39giampaolo.rodolasetfiles: + socket-repr2.patch
2013-04-09 21:47:32vstinnersetnosy: + vstinner
messages: + msg186453
2013-04-09 21:40:15neologixsetnosy: + neologix
messages: + msg186452
2013-04-09 16:34:17pitrousetmessages: + msg186440
2013-04-09 13:17:08giampaolo.rodolasetnosy: + pitrou
2013-04-09 13:16:10giampaolo.rodolacreate