Skip to content
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 rudimentary support for Python 3.10 #715

Merged
merged 5 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion eventlet/greenio/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
_original_socket = eventlet.patcher.original('socket').socket


socket_timeout = eventlet.timeout.wrap_is_timeout(socket.timeout)
if sys.version_info >= (3, 10):
socket_timeout = socket.timeout # Really, TimeoutError
else:
socket_timeout = eventlet.timeout.wrap_is_timeout(socket.timeout)


def socket_connect(descriptor, address):
Expand Down
5 changes: 4 additions & 1 deletion eventlet/greenio/py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,12 @@ def __exit__(self, *args):
FileIO=GreenFileIO,
os=_original_os,
))
if hasattr(_original_pyio, 'text_encoding'):
_open_environment['text_encoding'] = _original_pyio.text_encoding

_pyio_open = getattr(_original_pyio.open, '__wrapped__', _original_pyio.open)
_open = FunctionType(
six.get_function_code(_original_pyio.open),
six.get_function_code(_pyio_open),
_open_environment,
)

Expand Down
9 changes: 7 additions & 2 deletions eventlet/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ def fun(*args, **kwargs):
return fun


if isinstance(__builtins__, dict): # seen when running tests on py310, but HOW??
_timeout_err = __builtins__.get('TimeoutError', Timeout)
else:
_timeout_err = getattr(__builtins__, 'TimeoutError', Timeout)


def is_timeout(obj):
py3err = getattr(__builtins__, 'TimeoutError', Timeout)
return bool(getattr(obj, 'is_timeout', False)) or isinstance(obj, py3err)
return bool(getattr(obj, 'is_timeout', False)) or isinstance(obj, _timeout_err)
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def run_isolated(path, prefix='tests/isolated/', **kwargs):

def check_is_timeout(obj):
value_text = getattr(obj, 'is_timeout', '(missing)')
assert obj.is_timeout, 'type={0} str={1} .is_timeout={2}'.format(type(obj), str(obj), value_text)
assert eventlet.is_timeout(obj), 'type={0} str={1} .is_timeout={2}'.format(type(obj), str(obj), value_text)


@contextlib.contextmanager
Expand Down
5 changes: 4 additions & 1 deletion tests/backdoor_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import os.path
import sys

import eventlet

Expand All @@ -22,7 +23,9 @@ def test_server(self):
def _run_test_on_client_and_server(self, client, server_thread):
f = client.makefile('rw')
assert 'Python' in f.readline()
f.readline() # build info
if sys.version_info < (3, 10):
# Starting in py310, build info is included in version line
f.readline() # build info
f.readline() # help info
assert 'InteractiveConsole' in f.readline()
self.assertEqual('>>> ', f.read(4))
Expand Down