# Buggy code
def load(cls, env):  # type: (Env) -> InstalledRepository
    """
    Load installed packages.

    For now, it uses the pip "freeze" command.
    """
    repo = cls()

    for distribution in sorted(
        distributions(path=env.sys_path),
        key=lambda d: str(d._path),
    ):
        metadata = distribution.metadata
        name = metadata["name"]
        version = metadata["version"]
        package = Package(name, version, version)
        package.description = metadata.get("summary", "")

        repo.add_package(package)

        path = Path(distribution._path)
        is_standard_package = True
        try:
            path.relative_to(env.site_packages)
        except ValueError:
            is_standard_package = False

        if is_standard_package:
            continue

        src_path = env.path / "src"

        # A VCS dependency should have been installed
        # in the src directory. If not, it's a path dependency
        try:
            path.relative_to(src_path)

            from poetry.vcs.git import Git

            git = Git()
            revision = git.rev_parse("HEAD", src_path / package.name).strip()
            url = git.remote_url(src_path / package.name)

            package.source_type = "git"
            package.source_url = url
            package.source_reference = revision
        except ValueError:
            package.source_type = "directory"
            package.source_url = str(path.parent)

    return repo


# Traceback (TypeError)
% poetry update -v
Using virtualenv: C:\Users\garyd\devel\video-storage\venv-new
[TypeError]
expected str, bytes or os.PathLike object, not Path
Traceback (most recent call last):
File "C:\Users\garyd\.poetry\lib\poetry\_vendor\py3.7\clikit\console_application.py", line 131, in run
status_code = command.handle(parsed_args, io)
File "C:\Users\garyd\.poetry\lib\poetry\_vendor\py3.7\clikit\api\command\command.py", line 120, in handle
status_code = self._do_handle(args, io)
File "C:\Users\garyd\.poetry\lib\poetry\_vendor\py3.7\clikit\api\command\command.py", line 171, in _do_handle
return getattr(handler, handler_method)(args, io, self)
File "C:\Users\garyd\.poetry\lib\poetry\_vendor\py3.7\cleo\commands\command.py", line 92, in wrap_handle
return self.handle()
File "C:\Users\garyd\.poetry\lib\poetry\console\commands\update.py", line 36, in handle
self.io, self.env, self.poetry.package, self.poetry.locker, self.poetry.pool
File "C:\Users\garyd\.poetry\lib\poetry\installation\installer.py", line 55, in __init__
installed = self._get_installed()
File "C:\Users\garyd\.poetry\lib\poetry\installation\installer.py", line 507, in _get_installed
return InstalledRepository.load(self._env)
File "C:\Users\garyd\.poetry\lib\poetry\repositories\installed_repository.py", line 30, in load
path = Path(distribution._path)
File "C:\Users\garyd\AppData\Local\Programs\Python\Python37\lib\pathlib.py", line 1010, in __new__
self = cls._from_parts(args, init=False)

# Fixed code
def load(cls, env):  # type: (Env) -> InstalledRepository
    """
    Load installed packages.

    For now, it uses the pip "freeze" command.
    """
    repo = cls()

    for distribution in sorted(
        distributions(path=env.sys_path),
        key=lambda d: str(d._path),
    ):
        metadata = distribution.metadata
        name = metadata["name"]
        version = metadata["version"]
        package = Package(name, version, version)
        package.description = metadata.get("summary", "")

        repo.add_package(package)

        path = Path(str(distribution._path))
        is_standard_package = True
        try:
            path.relative_to(env.site_packages)
        except ValueError:
            is_standard_package = False

        if is_standard_package:
            continue

        src_path = env.path / "src"

        # A VCS dependency should have been installed
        # in the src directory. If not, it's a path dependency
        try:
            path.relative_to(src_path)

            from poetry.vcs.git import Git

            git = Git()
            revision = git.rev_parse("HEAD", src_path / package.name).strip()
            url = git.remote_url(src_path / package.name)

            package.source_type = "git"
            package.source_url = url
            package.source_reference = revision
        except ValueError:
            package.source_type = "directory"
            package.source_url = str(path.parent)

    return repo