@@ -8,12 +8,13 @@ to multiple files in parallel.
 import random
 import sys
 from mitmproxy import io, http
+import typing  # noqa
 
 
 class Writer:
     def __init__(self, path: str) -> None:
         if path == "-":
-            f = sys.stdout  # type: io.TextIO
+            f = sys.stdout  # type: typing.IO[typing.Any]
         else:
             f = open(path, "wb")
         self.w = io.FlowWriter(f)
"""
This script how to generate a mitmproxy dump file,
as it would also be generated by passing `-w` to mitmproxy.
In contrast to `-w`, this gives you full control over which
flows should be saved and also allows you to rotate files or log
to multiple files in parallel.
"""
import random
import sys
from mitmproxy import io, http


class Writer:
    def __init__(self, path: str) -> None:
        if path == "-":
            f = sys.stdout  # type: io.TextIO
        else:
            f = open(path, "wb")
        self.w = io.FlowWriter(f)

    def response(self, flow: http.HTTPFlow) -> None:
        if random.choice([True, False]):
            self.w.add(flow)


addons = [Writer(sys.argv[1])]

The FlowWriter only writes bytes, so this should really be `typing.IO[bytes]`. If that raises errors, that's a strong indicator that the code here does not work as intended. I'd be fine with removing the `if path == "-":` special case altogether.