Bug 1671356 [wpt PR 26102] - Remove a hack for mypy<0.790, a=testonly

Automatic update from web-platform-tests
Remove a hack for mypy<0.790 (#26102)

We have upgraded to mypy 0.790 in #26066, which brings us
https://github.com/python/typeshed/pull/4146.

Unfortunately, we still have to use io.open instead of the built-in open
because the "text mode" of open() in Python 2 doesn't really take text
(unicode).

Also made some drive-by stylistic changes.
--

wpt-commits: fdc3a462396df8af5d2d8f2e5277e98817ffbb9d
wpt-pr: 26102
This commit is contained in:
Robert Ma 2020-10-16 09:59:19 +00:00 коммит произвёл moz-wptsync-bot
Родитель 0c5f97f11d
Коммит 52ff8182d6
1 изменённых файлов: 17 добавлений и 11 удалений

Просмотреть файл

@ -1,9 +1,11 @@
import io
from six import ensure_text
MYPY = False
if MYPY:
# MYPY is set to True when run under Mypy.
from typing import Any
from typing import Optional
from typing import Text
from typing import AnyStr, Optional, Text
class GitHubChecksOutputter(object):
"""Provides a method to output data to be shown in the GitHub Checks UI.
@ -12,23 +14,27 @@ class GitHubChecksOutputter(object):
to enable developers to quickly understand what has gone wrong. The output
supports markdown format.
See https://docs.taskcluster.net/docs/reference/integrations/github/checks#custom-text-output-in-checks
https://docs.taskcluster.net/docs/reference/integrations/github/checks#custom-text-output-in-checks
"""
def __init__(self, path):
# type: (Text) -> None
self.path = path
def output(self, line):
# type: (Any) -> None
# TODO(stephenmcgruer): Once mypy 0.790 is released, we can change this
# to AnyStr, as that release teaches mypy about the mode flags of open.
# See https://github.com/python/typeshed/pull/4146
with open(self.path, 'a') as f:
f.write(line)
f.write('\n')
# type: (AnyStr) -> None
text = ensure_text(line)
# NOTE: mypy types the "text mode" of open() in Python 2 as BinaryIO,
# which makes sense as we cannot specify its encoding (it's
# platform-dependent), while io.open() is closer to open() in Python 3.
# TODO: use the built-in open() when we are Py3-only.
with io.open(self.path, mode="a") as f:
f.write(text)
f.write(u"\n")
__outputter = None
def get_gh_checks_outputter(filepath):
# type: (Optional[Text]) -> Optional[GitHubChecksOutputter]
"""Return the outputter for GitHub Checks output, if enabled.