gurudesh/pytracebugs huggingface dataset:
# Buggy code
def get_egg_info_files(sp_dir):
    for fn in os.listdir(sp_dir):
        if fn.endswith(".egg-link"):
            with open(join(sp_dir, fn), "r") as reader:
                for egg in get_egg_info_files(reader.readline().strip()):
                    yield egg
        if not fn.endswith((".egg", ".egg-info", ".dist-info")):
            continue
        path = join(sp_dir, fn)
        if isfile(path):
            yield path
        elif isdir(path):
            for path2 in [
                join(path, "PKG-INFO"),
                join(path, "EGG-INFO", "PKG-INFO"),
                join(path, "METADATA"),
            ]:
                if isfile(path2):
                    yield path2


# Traceback (FileNotFoundError)
"command": "/Users/hideki/anaconda/bin/conda list"
"user_agent": "conda/4.4.3 requests/2.14.2 CPython/3.5.2 Darwin/16.7.0 OSX/10.12.6"

Traceback (most recent call last):
File \"/Users/hideki/anaconda/lib/python3.5/site-packages/conda/exceptions.py\", line 722, in __call__
return func(*args, **kwargs)
File \"/Users/hideki/anaconda/lib/python3.5/site-packages/conda/cli/main.py\", line 78, in _main
exit_code = do_call(args, p)
File \"/Users/hideki/anaconda/lib/python3.5/site-packages/conda/cli/conda_argparse.py\", line 75, in do_call
exit_code = getattr(module, func_name)(args, parser)
File \"/Users/hideki/anaconda/lib/python3.5/site-packages/conda/cli/main_list.py\", line 150, in execute
show_channel_urls=context.show_channel_urls)
File \"/Users/hideki/anaconda/lib/python3.5/site-packages/conda/cli/main_list.py\", line 85, in print_packages
other_python = get_egg_info(prefix)
File \"/Users/hideki/anaconda/lib/python3.5/site-packages/conda/egg_info.py\", line 86, in get_egg_info
for path in get_egg_info_files(join(prefix, sp_dir)):
File \"/Users/hideki/anaconda/lib/python3.5/site-packages/conda/egg_info.py\", line 35, in get_egg_info_files
for egg in get_egg_info_files(reader.readline().strip()):
File \"/Users/hideki/anaconda/lib/python3.5/site-packages/conda/egg_info.py\", line 32, in get_egg_info_files
for fn in os.listdir(sp_dir):
FileNotFoundError: [Errno 2] No such file or directory: '/Users/hideki/darkflow'

# Fixed code
def get_egg_info_files(sp_dir):
    for fn in isdir(sp_dir) and os.listdir(sp_dir) or ():
        if fn.endswith(".egg-link"):
            with open(join(sp_dir, fn), "r") as reader:
                for egg in get_egg_info_files(reader.readline().strip()):
                    yield egg
        if not fn.endswith((".egg", ".egg-info", ".dist-info")):
            continue
        path = join(sp_dir, fn)
        if isfile(path):
            yield path
        elif isdir(path):
            for path2 in [
                join(path, "PKG-INFO"),
                join(path, "EGG-INFO", "PKG-INFO"),
                join(path, "METADATA"),
            ]:
                if isfile(path2):
                    yield path2
# Buggy code
def register_env(location):
    location = normpath(location)

    if "placehold_pl" in location:
        # Don't record envs created by conda-build.
        return

    if location in yield_lines(USER_ENVIRONMENTS_TXT_FILE):
        # Nothing to do. Location is already recorded in a known environments.txt file.
        return

    with open(USER_ENVIRONMENTS_TXT_FILE, "a") as fh:
        fh.write(location)
        fh.write("\n")


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "/Users/kfranz/continuum/conda/conda/core/link.py", line 535, in _execute_actions
action.execute()
File "/Users/kfranz/continuum/conda/conda/core/path_actions.py", line 876, in execute
register_env(self.target_prefix)
File "/Users/kfranz/continuum/conda/conda/core/envs_manager.py", line 28, in register_env
if location in yield_lines(USER_ENVIRONMENTS_TXT_FILE):
File "/Users/kfranz/continuum/conda/conda/gateways/disk/read.py", line 49, in yield_lines
if not line or line.startswith('#'):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 54: ordinal not in range(128)

# Fixed code
def register_env(location):
    location = normpath(location)

    if "placehold_pl" in location:
        # Don't record envs created by conda-build.
        return

    if location in yield_lines(USER_ENVIRONMENTS_TXT_FILE):
        # Nothing to do. Location is already recorded in a known environments.txt file.
        return

    with open(USER_ENVIRONMENTS_TXT_FILE, "a") as fh:
        fh.write(ensure_text_type(location))
        fh.write("\n")
# Buggy code
def close(self):
    if self.json:
        sys.stdout.write(
            '{"fetch":"%s","finished":true,"maxval":1,"progress":1}\n\0'
            % self.description
        )
        sys.stdout.flush()
    elif self.enabled:
        self.pbar.close()
    self.enabled = False


# Traceback (BrokenPipeError)
Traceback (most recent call last):
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/exceptions.py\", line 722, in __call__
return func(*args, **kwargs)
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/cli/main.py\", line 78, in _main
exit_code = do_call(args, p)
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/cli/conda_argparse.py\", line 75, in do_call
exit_code = getattr(module, func_name)(args, parser)
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/cli/main_create.py\", line 11, in execute
install(args, parser, 'create')
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/cli/install.py\", line 239, in install
handle_txn(progressive_fetch_extract, unlink_link_transaction, prefix, args, newenv)
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/cli/install.py\", line 265, in handle_txn
progressive_fetch_extract.execute()
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/core/package_cache.py\", line 543, in execute
exc = self._execute_actions(prec_or_spec, prec_actions)
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/core/package_cache.py\", line 595, in _execute_actions
progress_bar.close()
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/common/io.py\", line 376, in close
self.pbar.close()
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/_vendor/tqdm/_tqdm.py\", line 1054, in close
self.bar_format, self.postfix, self.unit_divisor))
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/_vendor/tqdm/_tqdm.py\", line 201, in print_status
fp_write('\\r' + s + (' ' * max(last_len[0] - len_s, 0)))
File \"/home/jon/anaconda3/lib/python3.6/site-packages/conda/_vendor/tqdm/_tqdm.py\", line 195, in fp_write
fp_flush()
BrokenPipeError: [Errno 32] Broken pipe

# Fixed code
def close(self):
    try:
        if self.json:
            sys.stdout.write(
                '{"fetch":"%s","finished":true,"maxval":1,"progress":1}\n\0'
                % self.description
            )
            sys.stdout.flush()
        elif self.enabled:
            self.pbar.close()
    except (IOError, OSError) as e:
        # Ignore BrokenPipeError and errors related to stdout or stderr being
        # closed by a downstream program.
        if e.errno not in (EPIPE, ESHUTDOWN):
            raise
    self.enabled = False
# Buggy code
def _make(field_name, value):
    if field_name not in IndexRecord.__fields__:
        raise CondaValueError("Cannot match on field %s" % (field_name,))
    elif isinstance(value, string_types):
        value = text_type(value)

    if hasattr(value, "match"):
        matcher = value
    elif field_name in _implementors:
        matcher = _implementors[field_name](value)
    elif text_type(value):
        matcher = StrMatch(value)
    else:
        raise NotImplementedError()

    return field_name, matcher


# Traceback (NotImplementedError)
Traceback (most recent call last):
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/exceptions.py\", line 683, in __call__
return func(*args, **kwargs)
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/cli/main.py\", line 78, in _main
exit_code = do_call(args, p)
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/cli/conda_argparse.py\", line 75, in do_call
exit_code = getattr(module, func_name)(args, parser)
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/cli/main_list.py\", line 150, in execute
show_channel_urls=context.show_channel_urls)
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/cli/main_list.py\", line 90, in print_packages
show_channel_urls=show_channel_urls)
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/cli/main_list.py\", line 52, in list_packages
info = is_linked(prefix, dist)
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/core/linked_data.py\", line 166, in is_linked
elif MatchSpec(dist).match(prefix_record):
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/models/match_spec.py\", line 67, in __call__
return super(MatchSpecType, cls).__call__(**parsed)
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/models/match_spec.py\", line 178, in __init__
self._match_components = self._build_components(**kwargs)
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/models/match_spec.py\", line 359, in _build_components
return frozendict(_make(key, value) for key, value in iteritems(kwargs))
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/models/match_spec.py\", line 359, in <genexpr>
return frozendict(_make(key, value) for key, value in iteritems(kwargs))
File \"/home/rob/miniconda3/lib/python3.6/site-packages/conda/models/match_spec.py\", line 355, in _make
raise NotImplementedError()
NotImplementedError

# Fixed code
def _make(field_name, value):
    if field_name not in IndexRecord.__fields__:
        raise CondaValueError("Cannot match on field %s" % (field_name,))
    elif isinstance(value, string_types):
        value = text_type(value)

    if hasattr(value, "match"):
        matcher = value
    elif field_name in _implementors:
        matcher = _implementors[field_name](value)
    else:
        matcher = StrMatch(text_type(value))

    return field_name, matcher
# Buggy code
def parse(self):
    if not self.raw:
        return

    self.update({"conda": []})

    for line in self.raw:
        if isinstance(line, dict):
            self.update(line)
        else:
            self["conda"].append(common.arg2spec(line))


# Traceback (TypeError)
$ cat environment.yml
dependencies:
- pip:

$ conda env create -n recreate --file=environment.yml
Fetching package metadata ...........
Solving package specifications: An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues

Current conda install:

platform : linux-64
conda version : 4.3.13
conda is private : False
conda-env version : 4.3.13
conda-build version : 2.1.5
python version : 3.5.2.final.0
requests version : 2.13.0
root environment : /opt/ts/services/miniconda.ext_public_miniconda/dist  (read only)
default environment : /opt/ts/services/miniconda.ext_public_miniconda/dist
envs directories : /nas/dft/ire/rhys/envs
/opt/ts/services/miniconda.ext_public_miniconda/dist/envs
/home/rhys/.conda/envs
package cache : /opt/ts/services/miniconda.ext_public_miniconda/dist/pkgs
/home/rhys/.conda/pkgs
channel URLs : http://python3.app.twosigma.com/conda/twosigma.com/ts/linux-64
http://python3.app.twosigma.com/conda/twosigma.com/ts/noarch
http://python3.app.twosigma.com/conda/twosigma.com/ext/linux-64
http://python3.app.twosigma.com/conda/twosigma.com/ext/noarch
http://python3.app.twosigma.com/conda/repo.continuum.io/pkgs/free/linux-64
http://python3.app.twosigma.com/conda/repo.continuum.io/pkgs/free/noarch
http://python3.app.twosigma.com/conda/repo.continuum.io/pkgs/pro/linux-64
http://python3.app.twosigma.com/conda/repo.continuum.io/pkgs/pro/noarch
config file : /home/rhys/.condarc
offline mode : False
user-agent : conda/4.3.13 requests/2.13.0 CPython/3.5.2 Linux/4.1.35-pv-ts2 debian/7.10 glibc/2.13
UID:GID : 11082:5000

`$ /opt/ts/services/miniconda.ext_public_miniconda/dist/bin/conda-env create -n recreate --file=environment.yml`

Traceback (most recent call last):
File "/opt/ts/services/miniconda.ext_public_miniconda/dist/lib/python3.5/site-packages/conda/exceptions.py", line 591, in conda_exception_handler
return_value = func(*args, **kwargs)
File "/opt/ts/services/miniconda.ext_public_miniconda/dist/lib/python3.5/site-packages/conda_env/cli/main_create.py", line 108, in execute
installer.install(prefix, pkg_specs, args, env)
File "/opt/ts/services/miniconda.ext_public_miniconda/dist/lib/python3.5/site-packages/conda_env/installers/pip.py", line 8, in install
pip_cmd = pip_args(prefix) + ['install', ] + specs
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'

# Fixed code
def parse(self):
    if not self.raw:
        return

    self.update({"conda": []})

    for line in self.raw:
        if isinstance(line, dict):
            self.update(line)
        else:
            self["conda"].append(common.arg2spec(line))

    if "pip" in self:
        if not self["pip"]:
            del self["pip"]
        if not any(MatchSpec(s).name == "pip" for s in self["conda"]):
            self["conda"].append("pip")
# Buggy code
def configure_parser(sub_parsers):
    l = sub_parsers.add_parser(
        "list",
        formatter_class=RawDescriptionHelpFormatter,
        description=description,
        help=description,
        epilog=example,
    )

    common.add_parser_json(l)

    l.set_defaults(func=execute)


# Traceback (AssertionError)
Traceback (most recent call last):
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\exceptions.py", line 632, in conda_exception_handler
return_value = func(*args, **kwargs)
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\cli\main.py", line 137, in _main
exit_code = args.func(args, p)
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\cli\main_install.py", line 80, in execute
install(args, parser, 'install')
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\cli\install.py", line 357, in install
execute_actions(actions, index, verbose=not context.quiet)
File "C:\Users\dbsr7927\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\plan.py", line 830, in execute_actions
execute_instructions(plan, index, verbose)
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\instructions.py", line 247, in execute_instructions
cmd(state, arg)
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\instructions.py", line 108, in UNLINKLINKTRANSACTION_CMD
txn.execute()
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 263, in execute
self.verify()
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 242, in verify
self.prepare()
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 149, in prepare
for pkg_info in self.packages_info_to_link)
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 149, in <genexpr>
for pkg_info in self.packages_info_to_link)
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\core\link.py", line 54, in determine_link_type
if hardlink_supported(source_test_file, target_prefix):
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\_vendor\auxlib\decorators.py", line 56, in _memoized_func
result = func(*args, **kwargs)
File "C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\conda\gateways\disk\test.py", line 84, in hardlink_supported
assert not lexists(test_file), test_file
AssertionError: C:\Users\xxxx\AppData\Local\Continuum\Anaconda3\.tmp.index.json

# Fixed code
def configure_parser(sub_parsers):
    list_parser = sub_parsers.add_parser(
        "list",
        formatter_class=RawDescriptionHelpFormatter,
        description=description,
        help=description,
        epilog=example,
    )

    common.add_parser_json(list_parser)

    list_parser.set_defaults(func=execute)
# Buggy code
def symlink_conda_hlp(prefix, root_dir, where, symlink_fn):
    scripts = ["conda", "activate", "deactivate"]
    prefix_where = join(prefix, where)
    if not isdir(prefix_where):
        os.makedirs(prefix_where)
    for f in scripts:
        root_file = join(root_dir, where, f)
        prefix_file = join(prefix_where, f)
        try:
            # try to kill stale links if they exist
            if os.path.lexists(prefix_file):
                os.remove(prefix_file)
            # if they're in use, they won't be killed.  Skip making new symlink.
            if not os.path.lexists(prefix_file):
                symlink_fn(root_file, prefix_file)
        except (IOError, OSError) as e:
            if os.path.lexists(prefix_file) and (
                e.errno in (errno.EPERM, errno.EACCES, errno.EROFS)
            ):
                log.debug(
                    "Cannot symlink {0} to {1}. Ignoring since link already exists.".format(
                        root_file, prefix_file
                    )
                )
            else:
                raise


# Traceback (OSError)
Traceback (most recent call last):
File "/symln_home/anaconda/bin/conda", line 6, in <module>
sys.exit(main())
File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/cli/main.py", line 48, in main
activate.main()
File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/cli/activate.py", line 163, in main
conda.install.symlink_conda(prefix, root_dir, shell)
File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/install.py", line 582, in symlink_conda
symlink_conda_hlp(prefix, root_dir, where, symlink_fn)
File "/Users/tomflem/anaconda/lib/python2.7/site-packages/conda/install.py", line 599, in symlink_conda_hlp
symlink_fn(root_file, prefix_file)
OSError: [Errno 17] File exists

# Fixed code
def symlink_conda_hlp(prefix, root_dir, where, symlink_fn):
    scripts = ["conda", "activate", "deactivate"]
    prefix_where = join(prefix, where)
    if not isdir(prefix_where):
        os.makedirs(prefix_where)
    for f in scripts:
        root_file = join(root_dir, where, f)
        prefix_file = join(prefix_where, f)
        try:
            # try to kill stale links if they exist
            if os.path.lexists(prefix_file):
                os.remove(prefix_file)
            # if they're in use, they won't be killed.  Skip making new symlink.
            if not os.path.lexists(prefix_file):
                symlink_fn(root_file, prefix_file)
        except (IOError, OSError) as e:
            if os.path.lexists(prefix_file) and (
                e.errno in (errno.EPERM, errno.EACCES, errno.EROFS, errno.EEXIST)
            ):
                log.debug(
                    "Cannot symlink {0} to {1}. Ignoring since link already exists.".format(
                        root_file, prefix_file
                    )
                )
            else:
                raise
# Buggy code
def compute_md5sum(file_full_path):
    if not isfile(file_full_path):
        raise CondaFileNotFoundError(file_full_path)

    hash_md5 = hashlib.md5()
    with open(file_full_path, "rb") as fh:
        for chunk in iter(partial(fh.read, 8192), b""):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()


# Traceback (conda.exceptions.CondaFileNotFoundError)
Traceback (most recent call last):
File "/conda/lib/python3.6/site-packages/conda/core/package_cache.py", line 502, in _execute_action
action.execute()
File "/conda/lib/python3.6/site-packages/conda/core/path_actions.py", line 739, in execute
source_md5sum = compute_md5sum(source_path)
File "/conda/lib/python3.6/site-packages/conda/gateways/disk/read.py", line 59, in compute_md5sum
raise CondaFileNotFoundError(file_full_path)
conda.exceptions.CondaFileNotFoundError: <unprintable CondaFileNotFoundError object>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/conda/lib/python3.6/site-packages/conda/exceptions.py", line 592, in conda_exception_handler
return_value = func(*args, **kwargs)
File "/conda/lib/python3.6/site-packages/conda/cli/main.py", line 134, in _main
exit_code = args.func(args, p)
File "/conda/lib/python3.6/site-packages/conda/cli/main_install.py", line 80, in execute
install(args, parser, 'install')
File "/conda/lib/python3.6/site-packages/conda/cli/install.py", line 200, in install
explicit(args.packages, prefix, verbose=not context.quiet)
File "/conda/lib/python3.6/site-packages/conda/misc.py", line 90, in explicit
pfe.execute()
File "/conda/lib/python3.6/site-packages/conda/core/package_cache.py", line 491, in execute
self._execute_action(action)
File "/conda/lib/python3.6/site-packages/conda/core/package_cache.py", line 507, in _execute_action
exceptions.append(CondaError(repr(e)))
File "/conda/lib/python3.6/site-packages/conda/__init__.py", line 43, in __repr__
return '%s: %s\n' % (self.__class__.__name__, text_type(self))
File "/conda/lib/python3.6/site-packages/conda/__init__.py", line 48, in __str__
return text_type(self.message % self._kwargs)
TypeError: must be real number, not dict

# Fixed code
def compute_md5sum(file_full_path):
    if not isfile(file_full_path):
        raise FileNotFoundError(file_full_path)

    hash_md5 = hashlib.md5()
    with open(file_full_path, "rb") as fh:
        for chunk in iter(partial(fh.read, 8192), b""):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()
# Buggy code
def __init__(
    self, parameter_name, parameter_value, source, wrong_type, valid_types, msg=None
):
    self.wrong_type = wrong_type
    self.valid_types = valid_types
    if msg is None:
        msg = "Parameter %s = %r declared in %s has type %s.\nValid types: %s." % (
            parameter_name,
            parameter_value,
            source,
            wrong_type,
            pretty_list(valid_types),
        )
    super(InvalidTypeError, self).__init__(
        parameter_name, parameter_value, source, msg=msg
    )


# Traceback (AttributeError)
`$ C:\Users\<username>\AppData\Local\Continuum\Anaconda3\Scripts\conda-script.py updat
e`

Traceback (most recent call last):
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\exceptions.py", line 573, in conda_exception_handler
return_value = func(*args, **kwargs)
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\cli\main.py", line 134, in _main
exit_code = args.func(args, p)
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\cli\main_update.py", line 65, in execute
install(args, parser, 'update')
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\cli\install.py", line 130, in install
context.validate_configuration()
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\common\configuration.py", line 838, in validate_configuration
raise_errors(tuple(chain.from_iterable((errors, post_errors))))
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\common\configuration.py", line 836, in <genexpr>
for name in self.parameter_names)
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\common\configuration.py", line 829, in _collect_validation_error
func(*args, **kwargs)
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\common\configuration.py", line 447, in __get__
result = typify_data_structure(self._merge(matches) if matches else self
.default,
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\common\configuration.py", line 664, in _merge
for match in relevant_matches)
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\common\configuration.py", line 664, in <genexpr>
for match in relevant_matches)
File "C:\Users\<username>\AppData\Local\Continuum\Anaconda3\lib\site-packages\co
nda\common\compat.py", line 71, in iteritems
return iter(d.items(**kw))
AttributeError: 'str' object has no attribute 'items'

# Fixed code
def __init__(
    self, parameter_name, parameter_value, source, wrong_type, valid_types, msg=None
):
    self.wrong_type = wrong_type
    self.valid_types = valid_types
    if msg is None:
        msg = "Parameter %s = %r declared in %s has type %s.\nValid types:\n%s" % (
            parameter_name,
            parameter_value,
            source,
            wrong_type,
            pretty_list(valid_types),
        )
    super(InvalidTypeError, self).__init__(
        parameter_name, parameter_value, source, msg=msg
    )
# Buggy code
def prefix_from_arg(arg, shelldict):
    from conda.base.context import context, locate_prefix_by_name

    "Returns a platform-native path"
    # MSYS2 converts Unix paths to Windows paths with unix seps
    # so we must check for the drive identifier too.
    if shelldict["sep"] in arg and not re.match("[a-zA-Z]:", arg):
        # strip is removing " marks, not \ - look carefully
        native_path = shelldict["path_from"](arg)
        if isdir(abspath(native_path.strip('"'))):
            prefix = abspath(native_path.strip('"'))
        else:
            raise CondaValueError("Could not find environment: %s" % native_path)
    else:
        prefix = locate_prefix_by_name(context, arg.replace("/", os.path.sep))
    return prefix


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def prefix_from_arg(arg, shelldict):
    from ..base.context import context, locate_prefix_by_name

    "Returns a platform-native path"
    # MSYS2 converts Unix paths to Windows paths with unix seps
    # so we must check for the drive identifier too.
    if shelldict["sep"] in arg and not re.match("[a-zA-Z]:", arg):
        # strip is removing " marks, not \ - look carefully
        native_path = shelldict["path_from"](arg)
        if isdir(abspath(native_path.strip('"'))):
            prefix = abspath(native_path.strip('"'))
        else:
            raise CondaValueError("Could not find environment: %s" % native_path)
    else:
        prefix = locate_prefix_by_name(context, arg.replace("/", os.path.sep))
    return prefix
# Buggy code
def _get_items(self):
    # TODO: Include .tar.bz2 files for local installs.
    from conda.core.index import get_index

    args = self.parsed_args
    call_dict = dict(
        channel_urls=args.channel or (),
        use_cache=True,
        prepend=not args.override_channels,
        unknown=args.unknown,
    )
    if hasattr(args, "platform"):  # in search
        call_dict["platform"] = args.platform
    index = get_index(**call_dict)
    return [record.name for record in index]


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def _get_items(self):
    # TODO: Include .tar.bz2 files for local installs.
    from ..core.index import get_index

    args = self.parsed_args
    call_dict = dict(
        channel_urls=args.channel or (),
        use_cache=True,
        prepend=not args.override_channels,
        unknown=args.unknown,
    )
    if hasattr(args, "platform"):  # in search
        call_dict["platform"] = args.platform
    index = get_index(**call_dict)
    return [record.name for record in index]
# Buggy code
def _get_items(self):
    from conda.core.linked_data import linked

    packages = linked(context.prefix_w_legacy_search)
    return [dist.quad[0] for dist in packages]


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def _get_items(self):
    from ..core.linked_data import linked

    packages = linked(context.prefix_w_legacy_search)
    return [dist.quad[0] for dist in packages]
# Buggy code
def get_index_trap(*args, **kwargs):
    """
    Retrieves the package index, but traps exceptions and reports them as
    JSON if necessary.
    """
    from conda.core.index import get_index

    kwargs.pop("json", None)
    return get_index(*args, **kwargs)


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def get_index_trap(*args, **kwargs):
    """
    Retrieves the package index, but traps exceptions and reports them as
    JSON if necessary.
    """
    from ..core.index import get_index

    kwargs.pop("json", None)
    return get_index(*args, **kwargs)
# Buggy code
def handle_envs_list(acc, output=True):
    from conda import misc

    if output:
        print("# conda environments:")
        print("#")

    def disp_env(prefix):
        fmt = "%-20s  %s  %s"
        default = "*" if prefix == context.default_prefix else " "
        name = ROOT_ENV_NAME if prefix == context.root_prefix else basename(prefix)
        if output:
            print(fmt % (name, default, prefix))

    for prefix in misc.list_prefixes():
        disp_env(prefix)
        if prefix != context.root_prefix:
            acc.append(prefix)

    if output:
        print()


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def handle_envs_list(acc, output=True):
    from .. import misc

    if output:
        print("# conda environments:")
        print("#")

    def disp_env(prefix):
        fmt = "%-20s  %s  %s"
        default = "*" if prefix == context.default_prefix else " "
        name = ROOT_ENV_NAME if prefix == context.root_prefix else basename(prefix)
        if output:
            print(fmt % (name, default, prefix))

    for prefix in misc.list_prefixes():
        disp_env(prefix)
        if prefix != context.root_prefix:
            acc.append(prefix)

    if output:
        print()
# Buggy code
def check_write(command, prefix, json=False):
    if inroot_notwritable(prefix):
        from conda.cli.help import root_read_only

        root_read_only(command, prefix, json=json)


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def check_write(command, prefix, json=False):
    if inroot_notwritable(prefix):
        from .help import root_read_only

        root_read_only(command, prefix, json=json)
# Buggy code
def get_user_site():
    site_dirs = []
    try:
        if not on_win:
            if exists(expanduser("~/.local/lib")):
                for path in listdir(expanduser("~/.local/lib/")):
                    if python_re.match(path):
                        site_dirs.append("~/.local/lib/%s" % path)
        else:
            if "APPDATA" not in os.environ:
                return site_dirs
            APPDATA = os.environ[str("APPDATA")]
            if exists(join(APPDATA, "Python")):
                site_dirs = [
                    join(APPDATA, "Python", i) for i in listdir(join(APPDATA, "PYTHON"))
                ]
    except (IOError, OSError) as e:
        log.debug("Error accessing user site directory.\n%r", e)
    return site_dirs


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def get_user_site():
    site_dirs = []
    try:
        if not on_win:
            if exists(expanduser("~/.local/lib")):
                python_re = re.compile("python\d\.\d")
                for path in listdir(expanduser("~/.local/lib/")):
                    if python_re.match(path):
                        site_dirs.append("~/.local/lib/%s" % path)
        else:
            if "APPDATA" not in os.environ:
                return site_dirs
            APPDATA = os.environ[str("APPDATA")]
            if exists(join(APPDATA, "Python")):
                site_dirs = [
                    join(APPDATA, "Python", i) for i in listdir(join(APPDATA, "PYTHON"))
                ]
    except (IOError, OSError) as e:
        log.debug("Error accessing user site directory.\n%r", e)
    return site_dirs
# Buggy code
def pretty_package(dist, pkg):
    from conda.utils import human_bytes

    pkg = dump_record(pkg)
    d = OrderedDict(
        [
            ("file name", dist.to_filename()),
            ("name", pkg["name"]),
            ("version", pkg["version"]),
            ("build string", pkg["build"]),
            ("build number", pkg["build_number"]),
            ("channel", dist.channel),
            ("size", human_bytes(pkg["size"])),
        ]
    )
    for key in sorted(set(pkg.keys()) - SKIP_FIELDS):
        d[key] = pkg[key]

    print()
    header = "%s %s %s" % (d["name"], d["version"], d["build string"])
    print(header)
    print("-" * len(header))
    for key in d:
        print("%-12s: %s" % (key, d[key]))
    print("dependencies:")
    for dep in pkg["depends"]:
        print("    %s" % dep)


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def pretty_package(dist, pkg):
    from ..utils import human_bytes

    pkg = dump_record(pkg)
    d = OrderedDict(
        [
            ("file name", dist.to_filename()),
            ("name", pkg["name"]),
            ("version", pkg["version"]),
            ("build string", pkg["build"]),
            ("build number", pkg["build_number"]),
            ("channel", dist.channel),
            ("size", human_bytes(pkg["size"])),
        ]
    )
    for key in sorted(set(pkg.keys()) - SKIP_FIELDS):
        d[key] = pkg[key]

    print()
    header = "%s %s %s" % (d["name"], d["version"], d["build string"])
    print(header)
    print("-" * len(header))
    for key in d:
        print("%-12s: %s" % (key, d[key]))
    print("dependencies:")
    for dep in pkg["depends"]:
        print("    %s" % dep)
# Buggy code
def get_local_urls():
    from conda.models.channel import get_conda_build_local_url

    return get_conda_build_local_url() or []


# Traceback (ImportError)
$ conda -h
An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues



Traceback (most recent call last):
File "/home/vmrguser/anaconda2/bin/conda", line 6, in <module>
sys.exit(conda.cli.main())
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main.py", line 164, in main
return conda_exception_handler(_main, *args)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 589, in conda_exception_handler
print_unexpected_error_message(e)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 543, in print_unexpected_error_message
info_stdout, info_stderr = get_info()
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/exceptions.py", line 513, in get_info
args.func(args, p)
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/cli/main_info.py", line 148, in execute
from conda.api import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/api.py", line 1, in <module>
from .core.index import get_index
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/index.py", line 9, in <module>
from .repodata import collect_all_repodata
File "/home/vmrguser/anaconda2/lib/python2.7/site-packages/conda/core/repodata.py", line 21, in <module>
from requests.packages.urllib3.exceptions import InsecureRequestWarning
ImportError: No module named packages.urllib3.exceptions

# Fixed code
def get_local_urls():
    from .models.channel import get_conda_build_local_url

    return get_conda_build_local_url() or []