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

really drop python<=3.7 #3391

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/chat/chatdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
define("debug", default=True, help="run in debug mode")


class MessageBuffer(object):
class MessageBuffer:
def __init__(self):
# cond is notified whenever the message cache is updated
self.cond = tornado.locks.Condition()
Expand Down
2 changes: 1 addition & 1 deletion demos/webspider/webspider.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def worker():
try:
await fetch_url(url)
except Exception as e:
print("Exception: %s %s" % (e, url))
print("Exception: {} {}".format(e, url))
dead.add(url)
finally:
q.task_done()
Expand Down
20 changes: 9 additions & 11 deletions maint/benchmark/chunk_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
except NameError:
xrange = range

define('port', default=8888)
define('num_chunks', default=1000)
define('chunk_size', default=2048)
define("port", default=8888)
define("num_chunks", default=1000)
define("chunk_size", default=2048)


class ChunkHandler(RequestHandler):
def get(self):
for i in xrange(options.num_chunks):
self.write('A' * options.chunk_size)
self.write("A" * options.chunk_size)
self.flush()
self.finish()


def main():
parse_command_line()
app = Application([('/', ChunkHandler)])
app.listen(options.port, address='127.0.0.1')
app = Application([("/", ChunkHandler)])
app.listen(options.port, address="127.0.0.1")

def callback(response):
response.rethrow()
Expand All @@ -40,16 +40,14 @@ def callback(response):

logging.warning("Starting fetch with curl client")
curl_client = CurlAsyncHTTPClient()
curl_client.fetch('http://localhost:%d/' % options.port,
callback=callback)
curl_client.fetch("http://localhost:%d/" % options.port, callback=callback)
IOLoop.current().start()

logging.warning("Starting fetch with simple client")
simple_client = SimpleAsyncHTTPClient()
simple_client.fetch('http://localhost:%d/' % options.port,
callback=callback)
simple_client.fetch("http://localhost:%d/" % options.port, callback=callback)
IOLoop.current().start()


if __name__ == '__main__':
if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions maint/benchmark/gen_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tornado import gen
from tornado.options import options, define, parse_command_line

define('num', default=10000, help='number of iterations')
define("num", default=10000, help="number of iterations")

# These benchmarks are delicate. They hit various fast-paths in the gen
# machinery in order to stay synchronous so we don't need an IOLoop.
Expand Down Expand Up @@ -43,11 +43,11 @@ def main():
parse_command_line()
t = Timer(e1)
results = t.timeit(options.num) / options.num
print('engine: %0.3f ms per iteration' % (results * 1000))
print("engine: %0.3f ms per iteration" % (results * 1000))
t = Timer(c1)
results = t.timeit(options.num) / options.num
print('coroutine: %0.3f ms per iteration' % (results * 1000))
print("coroutine: %0.3f ms per iteration" % (results * 1000))


if __name__ == '__main__':
if __name__ == "__main__":
main()
7 changes: 4 additions & 3 deletions maint/benchmark/parsing_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ def main():
except ValueError:
known_benchmarks = [benchmark.value for benchmark in Benchmark]
print(
"Unknown benchmark: '{}', supported values are: {}"
.format(options.benchmark, ", ".join(known_benchmarks))
"Unknown benchmark: '{}', supported values are: {}".format(
options.benchmark, ", ".join(known_benchmarks)
)
)
return

for _ in range(options.num_runs):
func()


if __name__ == '__main__':
if __name__ == "__main__":
main()
21 changes: 12 additions & 9 deletions maint/benchmark/template_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
from tornado.options import options, define, parse_command_line
from tornado.template import Template

define('num', default=100, help='number of iterations')
define('dump', default=False, help='print template generated code and exit')
define("num", default=100, help="number of iterations")
define("dump", default=False, help="print template generated code and exit")

context = {
'page_title': 'mitsuhiko\'s benchmark',
'table': [dict(a=1, b=2, c=3, d=4, e=5,
f=6, g=7, h=8, i=9, j=10) for x in range(1000)]
"page_title": "mitsuhiko's benchmark",
"table": [
dict(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10) for x in range(1000)
],
}

tmpl = Template("""\
tmpl = Template(
"""\
<!doctype html>
<html>
<head>
Expand Down Expand Up @@ -50,7 +52,8 @@
</div>
</body>
</html>\
""")
"""
)


def render():
Expand All @@ -64,8 +67,8 @@ def main():
sys.exit(0)
t = Timer(render)
results = t.timeit(options.num) / options.num
print('%0.3f ms per iteration' % (results * 1000))
print("%0.3f ms per iteration" % (results * 1000))


if __name__ == '__main__':
if __name__ == "__main__":
main()
15 changes: 11 additions & 4 deletions maint/scripts/custom_fixers/fix_future_imports.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Updates all source files to import the same set of __future__ directives.
"""

from lib2to3 import fixer_base
from lib2to3 import pytree
from lib2to3.pgen2 import token
Expand All @@ -20,10 +21,16 @@ def start_tree(self, tree, filename):
self.found_future_import = False

def new_future_import(self, old):
new = FromImport("__future__",
[Name("absolute_import", prefix=" "), Comma(),
Name("division", prefix=" "), Comma(),
Name("print_function", prefix=" ")])
new = FromImport(
"__future__",
[
Name("absolute_import", prefix=" "),
Comma(),
Name("division", prefix=" "),
Comma(),
Name("print_function", prefix=" "),
],
)
if old is not None:
new.prefix = old.prefix
return new
Expand Down
2 changes: 1 addition & 1 deletion maint/scripts/custom_fixers/fix_unicode_literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class FixUnicodeLiteral(fixer_base.BaseFix):

def transform(self, node, results):
arg = results["arg"]
node.replace(String('u' + arg.value, prefix=node.prefix))
node.replace(String("u" + arg.value, prefix=node.prefix))
25 changes: 14 additions & 11 deletions maint/scripts/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,45 @@
except ImportError:
pycares = None

define('family', default='unspec',
help='Address family to query: unspec, inet, or inet6')
define(
"family", default="unspec", help="Address family to query: unspec, inet, or inet6"
)


@gen.coroutine
def main():
args = parse_command_line()

if not args:
args = ['localhost', 'www.google.com',
'www.facebook.com', 'www.dropbox.com']
args = ["localhost", "www.google.com", "www.facebook.com", "www.dropbox.com"]

resolvers = [Resolver(), ThreadedResolver(), DefaultExecutorResolver()]

if twisted is not None:
from tornado.platform.twisted import TwistedResolver

resolvers.append(TwistedResolver())

if pycares is not None:
from tornado.platform.caresresolver import CaresResolver

resolvers.append(CaresResolver())

family = {
'unspec': socket.AF_UNSPEC,
'inet': socket.AF_INET,
'inet6': socket.AF_INET6,
"unspec": socket.AF_UNSPEC,
"inet": socket.AF_INET,
"inet6": socket.AF_INET6,
}[options.family]

for host in args:
print('Resolving %s' % host)
print("Resolving %s" % host)
for resolver in resolvers:
addrinfo = yield resolver.resolve(host, 80, family)
print('%s: %s' % (resolver.__class__.__name__,
pprint.pformat(addrinfo)))
print(
"{}: {}".format(resolver.__class__.__name__, pprint.pformat(addrinfo))
)
print()


if __name__ == '__main__':
if __name__ == "__main__":
IOLoop.instance().run_sync(main)
22 changes: 12 additions & 10 deletions maint/test/cython/cythonapp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ def test_decorated_coroutine(self):

class CythonArgReplacerTest(unittest.TestCase):
def test_arg_replacer_function(self):
replacer = ArgReplacer(cythonapp.function_with_args, 'two')
args = (1, 'old', 3)
replacer = ArgReplacer(cythonapp.function_with_args, "two")
args = (1, "old", 3)
kwargs = {}
self.assertEqual(replacer.get_old_value(args, kwargs), 'old')
self.assertEqual(replacer.replace('new', args, kwargs),
('old', [1, 'new', 3], {}))
self.assertEqual(replacer.get_old_value(args, kwargs), "old")
self.assertEqual(
replacer.replace("new", args, kwargs), ("old", [1, "new", 3], {})
)

def test_arg_replacer_method(self):
replacer = ArgReplacer(cythonapp.AClass().method_with_args, 'two')
args = (1, 'old', 3)
replacer = ArgReplacer(cythonapp.AClass().method_with_args, "two")
args = (1, "old", 3)
kwargs = {}
self.assertEqual(replacer.get_old_value(args, kwargs), 'old')
self.assertEqual(replacer.replace('new', args, kwargs),
('old', [1, 'new', 3], {}))
self.assertEqual(replacer.get_old_value(args, kwargs), "old")
self.assertEqual(
replacer.replace("new", args, kwargs), ("old", [1, "new", 3], {})
)
8 changes: 4 additions & 4 deletions maint/test/cython/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
if Cython is None:
ext_modules = None
else:
ext_modules = Cython.Build.cythonize('cythonapp.pyx')
ext_modules = Cython.Build.cythonize("cythonapp.pyx")

setup(
name='cythonapp',
py_modules=['cythonapp_test', 'pythonmodule'],
name="cythonapp",
py_modules=["cythonapp_test", "pythonmodule"],
ext_modules=ext_modules,
setup_requires='Cython>=0.23.1',
setup_requires="Cython>=0.23.1",
)
Loading
Loading