Skip to content

Commit b699824

Browse files
committed
Add type: ignore comments to make mypy happy
1 parent 9f72321 commit b699824

30 files changed

Lines changed: 153 additions & 148 deletions

‎tornado/auth.py‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ def get(self):
9292
import urlparse
9393
import urllib as urllib_parse
9494

95-
try:
96-
long # py2
97-
except NameError:
98-
long = int # py3
99-
10095

10196
class AuthError(Exception):
10297
pass

‎tornado/autoreload.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
import functools
8484
import logging
8585
import os
86-
import pkgutil
86+
import pkgutil # type: ignore
8787
import sys
8888
import traceback
8989
import types
@@ -112,7 +112,7 @@
112112
_watched_files = set()
113113
_reload_hooks = []
114114
_reload_attempted = False
115-
_io_loops = weakref.WeakKeyDictionary()
115+
_io_loops = weakref.WeakKeyDictionary() # type: ignore
116116

117117

118118
def start(io_loop=None, check_time=500):

‎tornado/curl_httpclient.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import collections
2222
import functools
2323
import logging
24-
import pycurl
24+
import pycurl # type: ignore
2525
import threading
2626
import time
2727
from io import BytesIO

‎tornado/gen.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def get(self):
9292

9393
try:
9494
try:
95-
from functools import singledispatch # py34+
95+
# py34+
96+
from functools import singledispatch # type: ignore
9697
except ImportError:
9798
from singledispatch import singledispatch # backport
9899
except ImportError:
@@ -108,9 +109,10 @@ def get(self):
108109

109110
try:
110111
try:
111-
from collections.abc import Generator as GeneratorType # py35+
112+
# py35+
113+
from collections.abc import Generator as GeneratorType # type: ignore
112114
except ImportError:
113-
from backports_abc import Generator as GeneratorType
115+
from backports_abc import Generator as GeneratorType # type: ignore
114116

115117
try:
116118
from inspect import isawaitable # py35+
@@ -121,7 +123,7 @@ def get(self):
121123
raise
122124
from types import GeneratorType
123125

124-
def isawaitable(x):
126+
def isawaitable(x): # type: ignore
125127
return False
126128

127129
if PY3:

‎tornado/httpclient.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,15 @@ def __init__(self, request, code, headers=None, buffer=None,
572572
self.request_time = request_time
573573
self.time_info = time_info or {}
574574

575-
def _get_body(self):
575+
@property
576+
def body(self):
576577
if self.buffer is None:
577578
return None
578579
elif self._body is None:
579580
self._body = self.buffer.getvalue()
580581

581582
return self._body
582583

583-
body = property(_get_body)
584-
585584
def rethrow(self):
586585
"""If there was an error on the request, raise an `HTTPError`."""
587586
if self.error:

‎tornado/httputil.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353
from ssl import SSLError
5454
except ImportError:
5555
# ssl is unavailable on app engine.
56-
class SSLError(Exception):
56+
class _SSLError(Exception):
5757
pass
58-
58+
# Hack around a mypy limitation. We can't simply put "type: ignore"
59+
# on the class definition itself; must go through an assignment.
60+
SSLError = _SSLError # type: ignore
5961

6062
# RFC 7230 section 3.5: a recipient MAY recognize a single LF as a line
6163
# terminator and ignore any preceding CR.
@@ -738,7 +740,7 @@ def parse_multipart_form_data(boundary, data, arguments, files):
738740
name = disp_params["name"]
739741
if disp_params.get("filename"):
740742
ctype = headers.get("Content-Type", "application/unknown")
741-
files.setdefault(name, []).append(HTTPFile(
743+
files.setdefault(name, []).append(HTTPFile( # type: ignore
742744
filename=disp_params["filename"], body=value,
743745
content_type=ctype))
744746
else:

‎tornado/iostream.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,29 @@
5858
_ERRNO_WOULDBLOCK = (errno.EWOULDBLOCK, errno.EAGAIN)
5959

6060
if hasattr(errno, "WSAEWOULDBLOCK"):
61-
_ERRNO_WOULDBLOCK += (errno.WSAEWOULDBLOCK,)
61+
_ERRNO_WOULDBLOCK += (errno.WSAEWOULDBLOCK,) # type: ignore
6262

6363
# These errnos indicate that a connection has been abruptly terminated.
6464
# They should be caught and handled less noisily than other errors.
6565
_ERRNO_CONNRESET = (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE,
6666
errno.ETIMEDOUT)
6767

6868
if hasattr(errno, "WSAECONNRESET"):
69-
_ERRNO_CONNRESET += (errno.WSAECONNRESET, errno.WSAECONNABORTED, errno.WSAETIMEDOUT)
69+
_ERRNO_CONNRESET += (errno.WSAECONNRESET, errno.WSAECONNABORTED, errno.WSAETIMEDOUT) # type: ignore
7070

7171
if sys.platform == 'darwin':
7272
# OSX appears to have a race condition that causes send(2) to return
7373
# EPROTOTYPE if called while a socket is being torn down:
7474
# http://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
7575
# Since the socket is being closed anyway, treat this as an ECONNRESET
7676
# instead of an unexpected error.
77-
_ERRNO_CONNRESET += (errno.EPROTOTYPE,)
77+
_ERRNO_CONNRESET += (errno.EPROTOTYPE,) # type: ignore
7878

7979
# More non-portable errnos:
8080
_ERRNO_INPROGRESS = (errno.EINPROGRESS,)
8181

8282
if hasattr(errno, "WSAEINPROGRESS"):
83-
_ERRNO_INPROGRESS += (errno.WSAEINPROGRESS,)
83+
_ERRNO_INPROGRESS += (errno.WSAEINPROGRESS,) # type: ignore
8484

8585

8686
class StreamClosedError(IOError):

‎tornado/locale.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
from tornado._locale_data import LOCALE_NAMES
5656

5757
_default_locale = "en_US"
58-
_translations = {}
58+
_translations = {} # type: dict
5959
_supported_locales = frozenset([_default_locale])
6060
_use_gettext = False
6161
CONTEXT_SEPARATOR = "\x04"

‎tornado/netutil.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@
5151
ssl_match_hostname = ssl.match_hostname
5252
SSLCertificateError = ssl.CertificateError
5353
elif ssl is None:
54-
ssl_match_hostname = SSLCertificateError = None
54+
ssl_match_hostname = SSLCertificateError = None # type: ignore
5555
else:
5656
import backports.ssl_match_hostname
5757
ssl_match_hostname = backports.ssl_match_hostname.match_hostname
58-
SSLCertificateError = backports.ssl_match_hostname.CertificateError
58+
SSLCertificateError = backports.ssl_match_hostname.CertificateError # type: ignore
5959

6060
if hasattr(ssl, 'SSLContext'):
6161
if hasattr(ssl, 'create_default_context'):
@@ -102,7 +102,7 @@
102102
_ERRNO_WOULDBLOCK = (errno.EWOULDBLOCK, errno.EAGAIN)
103103

104104
if hasattr(errno, "WSAEWOULDBLOCK"):
105-
_ERRNO_WOULDBLOCK += (errno.WSAEWOULDBLOCK,)
105+
_ERRNO_WOULDBLOCK += (errno.WSAEWOULDBLOCK,) # type: ignore
106106

107107
# Default backlog used when calling sock.listen()
108108
_DEFAULT_BACKLOG = 128
@@ -411,8 +411,8 @@ class ThreadedResolver(ExecutorResolver):
411411
All ``ThreadedResolvers`` share a single thread pool, whose
412412
size is set by the first one to be created.
413413
"""
414-
_threadpool = None
415-
_threadpool_pid = None
414+
_threadpool = None # type: ignore
415+
_threadpool_pid = None # type: int
416416

417417
def initialize(self, io_loop=None, num_threads=10):
418418
threadpool = ThreadedResolver._create_threadpool(num_threads)
@@ -516,4 +516,4 @@ def ssl_wrap_socket(socket, ssl_options, server_hostname=None, **kwargs):
516516
else:
517517
return context.wrap_socket(socket, **kwargs)
518518
else:
519-
return ssl.wrap_socket(socket, **dict(context, **kwargs))
519+
return ssl.wrap_socket(socket, **dict(context, **kwargs)) # type: ignore

‎tornado/platform/asyncio.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
except ImportError as e:
3535
# Asyncio itself isn't available; see if trollius is (backport to py26+).
3636
try:
37-
import trollius as asyncio
37+
import trollius as asyncio # type: ignore
3838
except ImportError:
3939
# Re-raise the original asyncio error, not the trollius one.
4040
raise e
@@ -213,4 +213,4 @@ def to_asyncio_future(tornado_future):
213213
return af
214214

215215
if hasattr(convert_yielded, 'register'):
216-
convert_yielded.register(asyncio.Future, to_tornado_future)
216+
convert_yielded.register(asyncio.Future, to_tornado_future) # type: ignore

0 commit comments

Comments
 (0)