Skip to content

Commit 52ff818

Browse files
Hexclesmoz-wptsync-bot
authored andcommitted
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 python/typeshed#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
1 parent 0c5f97f commit 52ff818

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

testing/web-platform/tests/tools/ci/tc/github_checks_output.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import io
2+
from six import ensure_text
3+
14
MYPY = False
25
if MYPY:
36
# MYPY is set to True when run under Mypy.
4-
from typing import Any
5-
from typing import Optional
6-
from typing import Text
7+
from typing import AnyStr, Optional, Text
8+
79

810
class GitHubChecksOutputter(object):
911
"""Provides a method to output data to be shown in the GitHub Checks UI.
@@ -12,23 +14,27 @@ class GitHubChecksOutputter(object):
1214
to enable developers to quickly understand what has gone wrong. The output
1315
supports markdown format.
1416
15-
See https://docs.taskcluster.net/docs/reference/integrations/github/checks#custom-text-output-in-checks
17+
https://docs.taskcluster.net/docs/reference/integrations/github/checks#custom-text-output-in-checks
1618
"""
1719
def __init__(self, path):
1820
# type: (Text) -> None
1921
self.path = path
2022

2123
def output(self, line):
22-
# type: (Any) -> None
23-
# TODO(stephenmcgruer): Once mypy 0.790 is released, we can change this
24-
# to AnyStr, as that release teaches mypy about the mode flags of open.
25-
# See https://github.com/python/typeshed/pull/4146
26-
with open(self.path, 'a') as f:
27-
f.write(line)
28-
f.write('\n')
24+
# type: (AnyStr) -> None
25+
text = ensure_text(line)
26+
# NOTE: mypy types the "text mode" of open() in Python 2 as BinaryIO,
27+
# which makes sense as we cannot specify its encoding (it's
28+
# platform-dependent), while io.open() is closer to open() in Python 3.
29+
# TODO: use the built-in open() when we are Py3-only.
30+
with io.open(self.path, mode="a") as f:
31+
f.write(text)
32+
f.write(u"\n")
2933

3034

3135
__outputter = None
36+
37+
3238
def get_gh_checks_outputter(filepath):
3339
# type: (Optional[Text]) -> Optional[GitHubChecksOutputter]
3440
"""Return the outputter for GitHub Checks output, if enabled.

0 commit comments

Comments
 (0)