Commit 69bcd83a authored by Jason Madden's avatar Jason Madden

Fix the name of the ``type`` param to gevent.socket.getaddrinfo on Python 3.

Previously it would produce a TypeError if a caller tried to pass it
as a keyword argument.

Add a test for this. Also add tests for smtpd under Python 3, which is
where the issue was discovered.

Fixes #960.
parent 4b736917
......@@ -14,8 +14,12 @@
``getaddrinfo`` when ``connect`` is called. Reported in :issue:`944`
by Bernie Hackett.
- Replace ``optparse`` module with ``argparse``. See :issue:`947`.
- Update to an unreleased version of ``tblib`` to fix :issue:`954`,
- Update to version 1.3.1 of ``tblib`` to fix :issue:`954`,
reported by ml31415.
- Fix the name of the ``type`` parameter to
:func:`gevent.socket.getaddrinfo` to be correct on Python 3. This
would cause callers using keyword arguments to raise a :exc:`TypeError`.
Reported in :issue:`960` by js6626069.
1.2.1 (2017-01-12)
==================
......
......@@ -73,7 +73,7 @@ import sys
from gevent.hub import get_hub
from gevent.hub import ConcurrentObjectUseError
from gevent.timeout import Timeout
from gevent._compat import string_types, integer_types
from gevent._compat import string_types, integer_types, PY3
from gevent._util import copy_globals
from gevent._util import _NONE
......@@ -271,6 +271,19 @@ def getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
"""
return get_hub().resolver.getaddrinfo(host, port, family, socktype, proto, flags)
if PY3:
# The name of the socktype param changed to type in Python 3.
# See https://github.com/gevent/gevent/issues/960
# Using inspect here to directly detect the condition is painful because we have to
# wrap it with a try/except TypeError because not all Python 2
# versions can get the args of a builtin; we also have to use a with to suppress
# the deprecation warning.
d = getaddrinfo.__doc__
def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0): # pylint:disable=function-redefined
return get_hub().resolver.getaddrinfo(host, port, family, type, proto, flags)
getaddrinfo.__doc__ = d
del d
def gethostbyaddr(ip_address):
"""
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -461,6 +461,48 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})):
self.assertGreaterEqual(delay, min_time)
def assertMonkeyPatchedFuncSignatures(self, mod_name, *func_names):
# We use inspect.getargspec because it's the only thing available
# in Python 2.7, but it is deprecated
# pylint:disable=deprecated-method
import inspect
import warnings
from gevent.monkey import get_original
# XXX: Very similar to gevent.monkey.patch_module. Should refactor?
gevent_module = getattr(__import__('gevent.' + mod_name), mod_name)
module_name = getattr(gevent_module, '__target__', mod_name)
funcs_given = True
if not func_names:
funcs_given = False
func_names = getattr(gevent_module, '__implements__')
for func_name in func_names:
gevent_func = getattr(gevent_module, func_name)
if not inspect.isfunction(gevent_func) and not funcs_given:
continue
func = get_original(module_name, func_name)
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
gevent_sig = inspect.getargspec(gevent_func)
sig = inspect.getargspec(func)
except TypeError:
if funcs_given:
raise
# Can't do this one. If they specifically asked for it,
# it's an error, otherwise it's not.
# Python 3 can check a lot more than Python 2 can.
continue
self.assertEqual(sig.args, gevent_sig.args, func_name)
# The next three might not actually matter?
self.assertEqual(sig.varargs, gevent_sig.varargs, func_name)
self.assertEqual(sig.keywords, gevent_sig.keywords, func_name)
self.assertEqual(sig.defaults, gevent_sig.defaults, func_name)
main = unittest.main
_original_Hub = gevent.hub.Hub
......
......@@ -336,6 +336,8 @@ class TestCreateConnection(greentest.TestCase):
class TestFunctions(greentest.TestCase):
@greentest.ignores_leakcheck
# Creating new types in the function takes a cycle to cleanup.
def test_wait_timeout(self):
# Issue #635
import gevent.socket
......@@ -360,8 +362,10 @@ class TestFunctions(greentest.TestCase):
finally:
gevent._socketcommon.get_hub = orig_get_hub
# Creating new types in the function takes a cycle to cleanup.
test_wait_timeout.ignore_leakcheck = True
def test_signatures(self):
# https://github.com/gevent/gevent/issues/960
self.assertMonkeyPatchedFuncSignatures('socket')
if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment