docs: def smart_open(filename: str, mode: str = 'Ur', buffering: int = -1,
                 encoding: str = None, errors: str = None, newline: str = None,
                 closefd: bool = True) -> IO:
      """
      Context manager (for use with ``with``) that opens a filename and provides
      a :class:`IO` object. If the filename is ``'-'``, however, then
      ``sys.stdin`` is used for reading and ``sys.stdout`` is used for writing.
      """
      # https://stackoverflow.com/questions/17602878/how-to-handle-both-with-open-and-sys-stdout-nicely  # noqa
      # https://stackoverflow.com/questions/1744989/read-from-file-or-stdin/29824059#29824059  # noqa
      if filename == '-':
          if mode is None or mode == '' or 'r' in mode:
              fh = sys.stdin
          else:
              fh = sys.stdout
      else:
          fh = open(filename, mode=mode,
                    buffering=buffering, encoding=encoding, errors=errors,
                    newline=newline, closefd=closefd)
      try:
          yield fh
      finally:
          if filename is not '-':
              fh.close()