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: socket.sendto raises incorrect exception when passed incorrect types
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: exarkun, ezio.melotti, falsetru, giampaolo.rodola, pitrou, python-dev
Priority: normal Keywords: needs review, patch

Created on 2010-10-21 17:22 by exarkun, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
issue10169.diff ezio.melotti, 2011-05-03 08:13 Patch against 2.7. review
issue10169-2.diff ezio.melotti, 2011-05-03 09:43 Patch against 2.7 w/ tests. review
Messages (5)
msg119320 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2010-10-21 17:22
>>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> s.bind(('', 0))
>>> s.sendto(u'hellé', s.getsockname())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sendto() takes exactly 3 arguments (2 given)
>>> s.sendto(3, s.getsockname())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sendto() takes exactly 3 arguments (2 given)
>>> s.sendto('hello', s.getsockname())

The TypeError gives the wrong explanation for what's wrong.
msg135020 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-05-03 08:13
The original code was trying to call PyArg_ParseTuple assuming 2 args and in case of failure (*any* failure) was starting over assuming 3 args.
The attached patch makes PyArg_ParseTuple accept 2 or 3 args and re-arranges the last two if 'flags' is passed.
The tests pass, but a few more tests should be added.
msg135022 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-05-03 09:43
Added tests and fixed all the problems they found.
msg135477 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-07 16:51
New changeset 7c3a20b5943a by Ezio Melotti in branch '2.7':
#10169: Fix argument parsing in socket.sendto() to avoid error masking.
msg135481 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2011-05-07 16:54
This turned out to be a duplicate of #5421 already fixed in 3.x, so I backported the patch and added the tests to 3.x too.
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54378
2011-05-07 16:54:44ezio.melottisetstatus: open -> closed
versions: - Python 3.1, Python 3.2
messages: + msg135481

resolution: fixed
stage: commit review -> resolved
2011-05-07 16:51:57python-devsetnosy: + python-dev
messages: + msg135477
2011-05-03 09:43:02ezio.melottisetkeywords: + needs review
files: + issue10169-2.diff
messages: + msg135022

stage: patch review -> commit review
2011-05-03 08:13:23ezio.melottisetfiles: + issue10169.diff

assignee: ezio.melotti

keywords: + patch
nosy: + ezio.melotti
messages: + msg135020
stage: patch review
2011-05-03 04:59:47falsetrusetnosy: + falsetru
2010-10-23 18:44:00giampaolo.rodolasetnosy: + giampaolo.rodola
2010-10-21 22:52:35eric.araujosetnosy: + pitrou

versions: + Python 3.1, - Python 2.6
2010-10-21 17:22:06exarkuncreate