From 8c5a41baf0bd2a1388d601e5b49d06b91997ccb8 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 6 Aug 2020 15:15:02 -0700 Subject: Remove support for end-of-life Python 2.7 (#1318) Remove support for end-of-life Python 2.7 Python 2.7 is end of life. It is no longer receiving bug fixes, including for security issues. Python 2.7 went EOL on 2020-01-01. For additional details on support Python versions, see: Supported: https://devguide.python.org/#status-of-python-branches EOL: https://devguide.python.org/devcycle/#end-of-life-branches Removing support for EOL Pythons will reduce testing and maintenance resources while allowing the library to move towards a modern Python 3 style. Python 2.7 users can continue to use the previous version of redis-py. Was able to simplify the code: - Removed redis._compat module - Removed __future__ imports - Removed object from class definition (all classes are new style) - Removed long (Python 3 unified numeric types) - Removed deprecated __nonzero__ method - Use simpler Python 3 super() syntax - Use unified OSError exception - Use yield from syntax Co-authored-by: Andy McCurdy --- benchmarks/base.py | 5 ++--- benchmarks/basic_operations.py | 12 +++--------- benchmarks/command_packer_benchmark.py | 5 ++--- 3 files changed, 7 insertions(+), 15 deletions(-) (limited to 'benchmarks') diff --git a/benchmarks/base.py b/benchmarks/base.py index 44e9341..8c13afe 100644 --- a/benchmarks/base.py +++ b/benchmarks/base.py @@ -3,10 +3,9 @@ import itertools import redis import sys import timeit -from redis._compat import izip -class Benchmark(object): +class Benchmark: ARGUMENTS = () def __init__(self): @@ -34,7 +33,7 @@ class Benchmark(object): group_names = [group['name'] for group in self.ARGUMENTS] group_values = [group['values'] for group in self.ARGUMENTS] for value_set in itertools.product(*group_values): - pairs = list(izip(group_names, value_set)) + pairs = list(zip(group_names, value_set)) arg_string = ', '.join(['%s=%s' % (p[0], p[1]) for p in pairs]) sys.stdout.write('Benchmark: %s... ' % arg_string) sys.stdout.flush() diff --git a/benchmarks/basic_operations.py b/benchmarks/basic_operations.py index a4b675d..9446343 100644 --- a/benchmarks/basic_operations.py +++ b/benchmarks/basic_operations.py @@ -1,13 +1,8 @@ -from __future__ import print_function import redis import time -import sys from functools import wraps from argparse import ArgumentParser -if sys.version_info[0] == 3: - long = int - def parse_args(): parser = ArgumentParser() @@ -47,9 +42,9 @@ def run(): def timer(func): @wraps(func) def wrapper(*args, **kwargs): - start = time.clock() + start = time.monotonic() ret = func(*args, **kwargs) - duration = time.clock() - start + duration = time.monotonic() - start if 'num' in kwargs: count = kwargs['num'] else: @@ -57,7 +52,7 @@ def timer(func): print('{} - {} Requests'.format(func.__name__, count)) print('Duration = {}'.format(duration)) print('Rate = {}'.format(count/duration)) - print('') + print() return ret return wrapper @@ -185,7 +180,6 @@ def hmset(conn, num, pipeline_size, data_size): set_data = {'str_value': 'string', 'int_value': 123456, - 'long_value': long(123456), 'float_value': 123456.0} for i in range(num): conn.hmset('hmset_key', set_data) diff --git a/benchmarks/command_packer_benchmark.py b/benchmarks/command_packer_benchmark.py index 1216df6..823a8c8 100644 --- a/benchmarks/command_packer_benchmark.py +++ b/benchmarks/command_packer_benchmark.py @@ -1,7 +1,6 @@ import socket from redis.connection import (Connection, SYM_STAR, SYM_DOLLAR, SYM_EMPTY, SYM_CRLF) -from redis._compat import imap from base import Benchmark @@ -29,7 +28,7 @@ class StringJoiningConnection(Connection): args_output = SYM_EMPTY.join([ SYM_EMPTY.join( (SYM_DOLLAR, str(len(k)).encode(), SYM_CRLF, k, SYM_CRLF)) - for k in imap(self.encoder.encode, args)]) + for k in map(self.encoder.encode, args)]) output = SYM_EMPTY.join( (SYM_STAR, str(len(args)).encode(), SYM_CRLF, args_output)) return output @@ -61,7 +60,7 @@ class ListJoiningConnection(Connection): buff = SYM_EMPTY.join( (SYM_STAR, str(len(args)).encode(), SYM_CRLF)) - for k in imap(self.encoder.encode, args): + for k in map(self.encoder.encode, args): if len(buff) > 6000 or len(k) > 6000: buff = SYM_EMPTY.join( (buff, SYM_DOLLAR, str(len(k)).encode(), SYM_CRLF)) -- cgit v1.2.1