From: Ben Darnell Date: Sun, 17 Apr 2016 17:01:41 +0000 (-0400) Subject: More type:ignore comments for `mypy --py2` X-Git-Tag: v4.4.0b1~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49fef5384a05ed021682ccd19fb36551638427c3;p=thirdparty%2Ftornado.git More type:ignore comments for `mypy --py2` --- diff --git a/tornado/gen.py b/tornado/gen.py index 8cffcc0bf..7ed8ba877 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -115,7 +115,8 @@ try: from backports_abc import Generator as GeneratorType # type: ignore try: - from inspect import isawaitable # py35+ + # py35+ + from inspect import isawaitable # type: ignore except ImportError: from backports_abc import isawaitable except ImportError: diff --git a/tornado/locale.py b/tornado/locale.py index db7411431..4f80fd366 100644 --- a/tornado/locale.py +++ b/tornado/locale.py @@ -51,6 +51,7 @@ import re from tornado import escape from tornado.log import gen_log +from tornado.util import PY3 from tornado._locale_data import LOCALE_NAMES @@ -147,11 +148,11 @@ def load_translations(directory, encoding=None): # in most cases but is common with CSV files because Excel # cannot read utf-8 files without a BOM. encoding = 'utf-8-sig' - try: + if PY3: # python 3: csv.reader requires a file open in text mode. # Force utf8 to avoid dependence on $LANG environment variable. f = open(full_path, "r", encoding=encoding) - except TypeError: + else: # python 2: csv can only handle byte strings (in ascii-compatible # encodings), which we decode below. Transcode everything into # utf8 before passing it to csv.reader. diff --git a/tornado/log.py b/tornado/log.py index c8821169a..1d10d3790 100644 --- a/tornado/log.py +++ b/tornado/log.py @@ -38,7 +38,7 @@ from tornado.escape import _unicode from tornado.util import unicode_type, basestring_type try: - import curses + import curses # type: ignore except ImportError: curses = None diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index d5a489963..e9a062cf1 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -30,7 +30,7 @@ from tornado import stack_context try: # Import the real asyncio module for py33+ first. Older versions of the # trollius backport also use this name. - import asyncio + import asyncio # type: ignore except ImportError as e: # Asyncio itself isn't available; see if trollius is (backport to py26+). try: diff --git a/tornado/testing.py b/tornado/testing.py index 625334220..82a8fa898 100644 --- a/tornado/testing.py +++ b/tornado/testing.py @@ -53,8 +53,8 @@ except ImportError: from types import GeneratorType # type: ignore if sys.version_info >= (3, 5): - iscoroutine = inspect.iscoroutine - iscoroutinefunction = inspect.iscoroutinefunction + iscoroutine = inspect.iscoroutine # type: ignore + iscoroutinefunction = inspect.iscoroutinefunction # type: ignore else: iscoroutine = iscoroutinefunction = lambda f: False @@ -69,9 +69,9 @@ if PY3: else: # On python 2, prefer unittest2 when available. try: - import unittest2 as unittest + import unittest2 as unittest # type: ignore except ImportError: - import unittest + import unittest # type: ignore _next_port = 10000