# Buggy code
def create_from_dists(cls, index, target_prefix, unlink_dists, link_dists):
    # This constructor method helps to patch into the 'plan' framework
    linked_packages_data_to_unlink = tuple(
        load_meta(target_prefix, dist) for dist in unlink_dists
    )

    log.debug(
        "instantiating UnlinkLinkTransaction with\n"
        "  target_prefix: %s\n"
        "  unlink_dists:\n"
        "    %s\n"
        "  link_dists:\n"
        "    %s\n",
        target_prefix,
        "\n    ".join(text_type(d) for d in unlink_dists),
        "\n    ".join(text_type(d) for d in link_dists),
    )

    pkg_dirs_to_link = tuple(
        PackageCache.get_entry_to_link(dist).extracted_package_dir
        for dist in link_dists
    )
    assert all(pkg_dirs_to_link)
    packages_info_to_link = tuple(
        read_package_info(index[dist], pkg_dir)
        for dist, pkg_dir in zip(link_dists, pkg_dirs_to_link)
    )

    return UnlinkLinkTransaction(
        target_prefix, linked_packages_data_to_unlink, packages_info_to_link
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/exceptions.py", line 591, in conda_exception_handler
return_value = func(*args, **kwargs)
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/cli/main.py", line 134, in _main
exit_code = args.func(args, p)
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/cli/main_update.py", line 65, in execute
install(args, parser, 'update')
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/cli/install.py", line 359, in install
execute_actions(actions, index, verbose=not context.quiet)
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/plan.py", line 800, in execute_actions
execute_instructions(plan, index, verbose)
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/instructions.py", line 247, in execute_instructions
cmd(state, arg)
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/instructions.py", line 108, in UNLINKLINKTRANSACTION_CMD
txn.execute()
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/core/link.py", line 262, in execute
self.verify()
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/core/link.py", line 241, in verify
self.prepare()
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/core/link.py", line 163, in prepare
for lnkd_pkg_data in self.linked_packages_data_to_unlink)
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/core/link.py", line 163, in <genexpr>
for lnkd_pkg_data in self.linked_packages_data_to_unlink)
File "/Users/luisaalanizcastillo/anaconda/lib/python3.6/site-packages/conda/core/link.py", line 65, in make_unlink_actions
for trgt in linked_package_data.files)
AttributeError: 'NoneType' object has no attribute 'files'

# Fixed code
def create_from_dists(cls, index, target_prefix, unlink_dists, link_dists):
    # This constructor method helps to patch into the 'plan' framework
    lnkd_pkg_data = (load_meta(target_prefix, dist) for dist in unlink_dists)
    # TODO: figure out if this filter shouldn't be an assert not None
    linked_packages_data_to_unlink = tuple(lpd for lpd in lnkd_pkg_data if lpd)

    log.debug(
        "instantiating UnlinkLinkTransaction with\n"
        "  target_prefix: %s\n"
        "  unlink_dists:\n"
        "    %s\n"
        "  link_dists:\n"
        "    %s\n",
        target_prefix,
        "\n    ".join(text_type(d) for d in unlink_dists),
        "\n    ".join(text_type(d) for d in link_dists),
    )

    pkg_dirs_to_link = tuple(
        PackageCache.get_entry_to_link(dist).extracted_package_dir
        for dist in link_dists
    )
    assert all(pkg_dirs_to_link)
    packages_info_to_link = tuple(
        read_package_info(index[dist], pkg_dir)
        for dist, pkg_dir in zip(link_dists, pkg_dirs_to_link)
    )

    return UnlinkLinkTransaction(
        target_prefix, linked_packages_data_to_unlink, packages_info_to_link
    )