# Buggy code
def open_by_relpath(self, path, remote=None, mode="r", encoding=None):
    """Opens a specified resource as a file descriptor"""

    tree = RepoTree(self, stream=True, subrepos=True)
    path = os.path.join(self.root_dir, path)
    try:
        with self.state:
            with tree.open(
                path,
                mode=mode,
                encoding=encoding,
                remote=remote,
            ) as fobj:
                yield fobj
    except FileNotFoundError as exc:
        raise FileMissingError(path) from exc
    except IsADirectoryError as exc:
        raise DvcIsADirectoryError(f"'{path}' is a directory") from exc


# Traceback (AssertionError)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-x-xxxxxxxxxxxx> in <module>
----> 1 with open('test/foo') as file:
2     pass
3

.../python3.6/contextlib.py in __enter__(self)
79     def __enter__(self):
80         try:
---> 81             return next(self.gen)
82         except StopIteration:
83             raise RuntimeError("generator didn't yield") from None

.../python3.6/site-packages/dvc/api.py in _open(path, repo, rev, remote, mode, encoding)
82     with _make_repo(repo, rev=rev) as _repo:
83         with _repo.open_by_relpath(
---> 84             path, remote=remote, mode=mode, encoding=encoding
85         ) as fd:
86             yield fd

.../python3.6/contextlib.py in __enter__(self)
79     def __enter__(self):
80         try:
---> 81             return next(self.gen)
82         except StopIteration:
83             raise RuntimeError("generator didn't yield") from None

.../python3.6/site-packages/dvc/repo/__init__.py in open_by_relpath(self, path, remote, mode, encoding)
616             with self.state:
617                 with tree.open(
--> 618                     path, mode=mode, encoding=encoding, remote=remote,
619                 ) as fobj:
620                     yield fobj

.../python3.6/site-packages/dvc/tree/repo.py in open(self, path, mode, encoding, **kwargs)
157                 raise
158
--> 159         return dvc_tree.open(path, mode=mode, encoding=encoding, **kwargs)
160
161     def exists(

.../python3.6/site-packages/dvc/tree/dvc.py in open(self, path, mode, encoding, remote)
80             if self.stream:
81                 if out.is_dir_checksum:
---> 82                     checksum = self._get_granular_checksum(path, out)
83                 else:
84                     checksum = out.hash_info.value

.../python3.6/site-packages/dvc/tree/dvc.py in _get_granular_checksum(self, path, out, remote)
47
48     def _get_granular_checksum(self, path, out, remote=None):
---> 49         assert isinstance(path, PathInfo)
50         if not self.fetch and not self.stream:
51             raise FileNotFoundError

AssertionError:

# Fixed code
def open_by_relpath(self, path, remote=None, mode="r", encoding=None):
    """Opens a specified resource as a file descriptor"""

    tree = RepoTree(self, stream=True, subrepos=True)
    path = PathInfo(self.root_dir) / path
    try:
        with self.state:
            with tree.open(
                path,
                mode=mode,
                encoding=encoding,
                remote=remote,
            ) as fobj:
                yield fobj
    except FileNotFoundError as exc:
        raise FileMissingError(path) from exc
    except IsADirectoryError as exc:
        raise DvcIsADirectoryError(f"'{path}' is a directory") from exc