Skip to content

Commit e86d3a3

Browse files
committed
Remove a hack for mypy<0.790
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 to make mypy happy in Python 2, because open() is still typed as BinaryIO unconditionally in Python 2.
1 parent 9df1f87 commit e86d3a3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

tools/ci/tc/github_checks_output.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import io
2+
13
MYPY = False
24
if MYPY:
35
# MYPY is set to True when run under Mypy.
4-
from typing import Any
5-
from typing import Optional
6-
from typing import Text
6+
from typing import Optional, Text, TextIO
7+
78

89
class GitHubChecksOutputter(object):
910
"""Provides a method to output data to be shown in the GitHub Checks UI.
@@ -19,16 +20,17 @@ def __init__(self, path):
1920
self.path = path
2021

2122
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:
23+
# type: (Text) -> None
24+
# mypy always casts open() as BinaryIO in Python 2 regardless of the mode.
25+
# TODO(Hexcles): use the built-in open() when we are Py3-only.
26+
with io.open(self.path, mode="a") as f:
2727
f.write(line)
2828
f.write('\n')
2929

3030

3131
__outputter = None
32+
33+
3234
def get_gh_checks_outputter(filepath):
3335
# type: (Optional[Text]) -> Optional[GitHubChecksOutputter]
3436
"""Return the outputter for GitHub Checks output, if enabled.

0 commit comments

Comments
 (0)