# Buggy code
def _get_granular_checksum(self, path, out, remote=None):
    assert isinstance(path, PathInfo)
    if not self.fetch and not self.stream:
        raise FileNotFoundError
    dir_cache = out.get_dir_cache(remote=remote)
    for entry in dir_cache:
        entry_relpath = entry[out.tree.PARAM_RELPATH]
        if os.name == "nt":
            entry_relpath = entry_relpath.replace("/", os.sep)
        if path == out.path_info / entry_relpath:
            return entry[out.tree.PARAM_CHECKSUM]
    raise FileNotFoundError


# 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 _get_granular_checksum(self, path_info: PathInfo, out: "BaseOutput", remote=None):
    assert isinstance(path_info, PathInfo)
    if not self.fetch and not self.stream:
        raise FileNotFoundError
    dir_cache = out.get_dir_cache(remote=remote)
    for entry in dir_cache:
        entry_relpath = entry[out.tree.PARAM_RELPATH]
        if os.name == "nt":
            entry_relpath = entry_relpath.replace("/", os.sep)
        if path_info == out.path_info / entry_relpath:
            return entry[out.tree.PARAM_CHECKSUM]
    raise FileNotFoundError