Commit 47a31554 authored by Jason Madden's avatar Jason Madden

Fix argument names for socketpair and fromfd. Exclude differences on PyPy.

parent 21a3bb0d
...@@ -19,7 +19,14 @@ ...@@ -19,7 +19,14 @@
- Fix the name of the ``type`` parameter to - Fix the name of the ``type`` parameter to
:func:`gevent.socket.getaddrinfo` to be correct on Python 3. This :func:`gevent.socket.getaddrinfo` to be correct on Python 3. This
would cause callers using keyword arguments to raise a :exc:`TypeError`. would cause callers using keyword arguments to raise a :exc:`TypeError`.
Reported in :issue:`960` by js6626069. Reported in :issue:`960` by js6626069. Likewise, correct the
argument names for ``fromfd`` and ``socketpair`` on Python 2,
although they cannot be called wit keyword arguments under CPython.
.. note:: The ``gethost*`` functions take different argument names
under CPython and PyPy. gevent follows the CPython
convention, although these functions cannot be called with
keyword arguments on CPython.
1.2.1 (2017-01-12) 1.2.1 (2017-01-12)
================== ==================
......
...@@ -499,8 +499,9 @@ SocketType = socket ...@@ -499,8 +499,9 @@ SocketType = socket
if hasattr(_socket, 'socketpair'): if hasattr(_socket, 'socketpair'):
def socketpair(*args): def socketpair(family=getattr(_socket, 'AF_UNIX', _socket.AF_INET),
one, two = _socket.socketpair(*args) type=_socket.SOCK_STREAM, proto=0):
one, two = _socket.socketpair(family, type, proto)
result = socket(_sock=one), socket(_sock=two) result = socket(_sock=one), socket(_sock=two)
if PYPY: if PYPY:
one._drop() one._drop()
...@@ -511,8 +512,8 @@ elif 'socketpair' in __implements__: ...@@ -511,8 +512,8 @@ elif 'socketpair' in __implements__:
if hasattr(_socket, 'fromfd'): if hasattr(_socket, 'fromfd'):
def fromfd(*args): def fromfd(fd, family, type, proto=0):
s = _socket.fromfd(*args) s = _socket.fromfd(fd, family, type, proto)
result = socket(_sock=s) result = socket(_sock=s)
if PYPY: if PYPY:
s._drop() s._drop()
......
...@@ -288,7 +288,7 @@ if PY3: ...@@ -288,7 +288,7 @@ if PY3:
def gethostbyaddr(ip_address): def gethostbyaddr(ip_address):
""" """
gethostbyaddr(host) -> (name, aliaslist, addresslist) gethostbyaddr(ip_address) -> (name, aliaslist, addresslist)
Return the true host name, a list of aliases, and a list of IP addresses, Return the true host name, a list of aliases, and a list of IP addresses,
for a host. The host argument is a string giving a host name or IP number. for a host. The host argument is a string giving a host name or IP number.
......
...@@ -461,7 +461,7 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})): ...@@ -461,7 +461,7 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})):
self.assertGreaterEqual(delay, min_time) self.assertGreaterEqual(delay, min_time)
def assertMonkeyPatchedFuncSignatures(self, mod_name, *func_names): def assertMonkeyPatchedFuncSignatures(self, mod_name, func_names=(), exclude=()):
# We use inspect.getargspec because it's the only thing available # We use inspect.getargspec because it's the only thing available
# in Python 2.7, but it is deprecated # in Python 2.7, but it is deprecated
# pylint:disable=deprecated-method # pylint:disable=deprecated-method
...@@ -478,6 +478,8 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})): ...@@ -478,6 +478,8 @@ class TestCase(TestCaseMetaClass("NewBase", (BaseTestCase,), {})):
func_names = getattr(gevent_module, '__implements__') func_names = getattr(gevent_module, '__implements__')
for func_name in func_names: for func_name in func_names:
if func_name in exclude:
continue
gevent_func = getattr(gevent_module, func_name) gevent_func = getattr(gevent_module, func_name)
if not inspect.isfunction(gevent_func) and not funcs_given: if not inspect.isfunction(gevent_func) and not funcs_given:
continue continue
......
...@@ -365,7 +365,16 @@ class TestFunctions(greentest.TestCase): ...@@ -365,7 +365,16 @@ class TestFunctions(greentest.TestCase):
def test_signatures(self): def test_signatures(self):
# https://github.com/gevent/gevent/issues/960 # https://github.com/gevent/gevent/issues/960
self.assertMonkeyPatchedFuncSignatures('socket') exclude = []
if greentest.PYPY:
# Up through at least PyPy 5.7.1, they define these as
# gethostbyname(host), whereas the official CPython argument name
# is hostname. But cpython doesn't allow calling with keyword args.
# Likewise for gethostbyaddr: PyPy uses host, cpython uses ip_address
exclude.append('gethostbyname')
exclude.append('gethostbyname_ex')
exclude.append('gethostbyaddr')
self.assertMonkeyPatchedFuncSignatures('socket', exclude=exclude)
if __name__ == '__main__': 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