gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _load_baseline_from_dict(cls, data):
    """Initializes a SecretsCollection object from dictionary.

    :type data: dict
    :param data: properly formatted dictionary to load SecretsCollection from.

    :rtype: SecretsCollection
    :raises: IOError
    """
    result = SecretsCollection()
    if not all(
        key in data
        for key in (
            "exclude_regex",
            "plugins_used",
            "results",
            "version",
        )
    ):
        raise IOError

    result.exclude_regex = data["exclude_regex"]

    plugins = []
    for plugin in data["plugins_used"]:
        plugin_classname = plugin.pop("name")
        plugins.append(initialize.from_plugin_classname(plugin_classname, **plugin))
    result.plugins = tuple(plugins)

    for filename in data["results"]:
        result.data[filename] = {}

        for item in data["results"][filename]:
            secret = PotentialSecret(
                item["type"],
                filename,
                item["line_number"],
                "will be replaced",
            )
            secret.secret_hash = item["hashed_secret"]
            result.data[filename][secret] = secret

    result.version = data["version"]

    return result


# Traceback (KeyError)
Traceback (most recent call last):
File "/hey/three_six/bin/detect-secrets", line 11, in <module>
sys.exit(main())
File "/hey/three_six/lib/python3.6/site-packages/detect_secrets/main.py", line 27, in main
log.set_debug_level(args.verbose)
File "/hey/three_six/lib/python3.6/site-packages/detect_secrets/core/log.py", line 46, in _set_debug_level
self.setLevel(mapping[debug_level])
KeyError: 3

# Fixed code
def _load_baseline_from_dict(cls, data):
    """Initializes a SecretsCollection object from dictionary.

    :type data: dict
    :param data: properly formatted dictionary to load SecretsCollection from.

    :rtype: SecretsCollection
    :raises: IOError
    """
    result = SecretsCollection()
    if not all(
        key in data
        for key in (
            "exclude_regex",
            "plugins_used",
            "results",
            "version",
        )
    ):
        raise IOError

    result.exclude_regex = data["exclude_regex"]

    plugins = []
    for plugin in data["plugins_used"]:
        plugin_classname = plugin.pop("name")
        plugins.append(initialize.from_plugin_classname(plugin_classname, **plugin))
    result.plugins = tuple(plugins)

    for filename in data["results"]:
        result.data[filename] = {}

        for item in data["results"][filename]:
            secret = PotentialSecret(
                item["type"],
                filename,
                item["line_number"],
                secret="will be replaced",
                is_secret=item.get("is_secret"),
            )
            secret.secret_hash = item["hashed_secret"]
            result.data[filename][secret] = secret

    result.version = data["version"]

    return result
# Buggy code
def __gt__(self, other):
    return (other + 1) <= self


# Traceback (AttributeError)
AttributeError                            Traceback (most recent call last)
<ipython-input-10-c55d3fcd7179> in <module>
2 t2 = torch.tensor([1.2, 1]).fix_precision()#.share(*workers, crypto_provider=crypto_provider, protocol="fss", requires_grad=True)
3
----> 4 t1 > t2

~/code/PySyft/syft/generic/frameworks/hook/hook.py in overloaded_native_method(self, *args, **kwargs)
218                 # Send the new command to the appropriate class and get the response
219                 method = getattr(new_self, method_name)
--> 220                 response = method(*new_args, **new_kwargs)
221
222                 # For inplace methods, just directly return self

~/code/PySyft/syft/generic/frameworks/overload.py in _hook_method_args(self, *args, **kwargs)
25
26             # Send it to the appropriate class and get the response
---> 27             response = attr(self, new_self, *new_args, **new_kwargs)
28
29             # Put back SyftTensor on the tensors found in the response

~/code/PySyft/syft/frameworks/torch/tensors/interpreters/precision.py in __gt__(self, _self, other)
821     def __gt__(self, _self, other):
822         print("FPT gt", _self, other)
--> 823         result = _self.__gt__(other)
824         return result.type(self.torch_dtype) * self.base ** self.precision_fractional
825

~/code/PySyft/syft/frameworks/torch/mpc/__init__.py in method(self, *args, **kwargs)
33         def method(self, *args, **kwargs):
34             f = protocol_store[(name, self.protocol)]
---> 35             return f(self, *args, **kwargs)
36
37         return method

~/code/PySyft/syft/frameworks/torch/tensors/interpreters/additive_shared.py in __gt__(self, other)
938     @crypto_protocol("fss")
939     def __gt__(self, other):
--> 940         return (other + 1) <= self
941
942     def ge(self, other):

~/code/PySyft/syft/generic/frameworks/hook/hook.py in overloaded_native_method(self, *args, **kwargs)
156                     # arguments
157                     if not isinstance(args[0].child, PointerTensor):
--> 158                         self = type(args[0].child)().on(self, wrap=True)
159                         args = [args[0]]
160                         return overloaded_native_method(self, *args, **kwargs)

AttributeError: 'dict' object has no attribute 'on'

# Fixed code
def __gt__(self, other):
    return -self <= -(other + 1)
# Buggy code
def create_wrapper(cls, wrapper_type):
    # Note this overrides FrameworkHook.create_wrapper, so it must conform to
    # that classmethod's signature
    assert wrapper_type is None or wrapper_type == torch.Tensor, (
        "TorchHook only uses torch.Tensor wrappers"
    )

    return torch.Tensor()


# Traceback (PureTorchTensorFoundError)
WARNING: Logging before flag parsing goes to stderr.
W0813 08:46:34.190028 140520788572032 secure_random.py:26] Falling back to insecure randomness since the required custom op could not be found for the installed version of TensorFlow. Fix this by compiling custom ops. Missing file was '/usr/local/lib/python3.6/dist-packages/tf_encrypted/operations/secure_random/secure_random_module_tf_1.14.0.so'
W0813 08:46:34.211576 140520788572032 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/tf_encrypted/session.py:26: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

0it [00:00, ?it/s]

Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ../data/cifar-10-python.tar.gz

170500096it [00:04, 40609204.86it/s]

---------------------------------------------------------------------------

PureTorchTensorFoundError                 Traceback (most recent call last)

/content/PySyft/syft/frameworks/torch/tensors/interpreters/native.py in handle_func_command(cls, command)
300             new_args, new_kwargs, new_type, args_type = syft.frameworks.torch.hook_args.unwrap_args_from_function(
--> 301                 cmd, args, kwargs, return_args_type=True
302             )

16 frames

PureTorchTensorFoundError:


During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in batch_norm(input, running_mean, running_var, weight, bias, training, momentum, eps)
1695     return torch.batch_norm(
1696         input, weight, bias, running_mean, running_var,
-> 1697         training, momentum, eps, torch.backends.cudnn.enabled
1698     )
1699

RuntimeError: running_mean should contain 3 elements not 32

# Fixed code
def create_wrapper(cls, wrapper_type):
    # Note this overrides FrameworkHook.create_wrapper, so it must conform to
    # that classmethod's signature
    if wrapper_type is None or wrapper_type == torch.Tensor:
        return torch.Tensor()
    elif isinstance(wrapper_type, torch.dtype):
        return torch.tensor([], dtype=wrapper_type)
    else:
        raise ValueError(
            "Wrapper type should be None, torch.Tensor, or a torch.dtype like torch.long"
        )
# Buggy code
def module_get_(nn_self):
    """overloads torch.nn instances with get method so that parameters could be sent back to owner"""
    for p in nn_self.parameters():
        p.get_()

    if isinstance(nn_self.forward, Plan):
        nn_self.forward.get()

    return nn_self


# Traceback (PureTorchTensorFoundError)
WARNING: Logging before flag parsing goes to stderr.
W0813 08:46:34.190028 140520788572032 secure_random.py:26] Falling back to insecure randomness since the required custom op could not be found for the installed version of TensorFlow. Fix this by compiling custom ops. Missing file was '/usr/local/lib/python3.6/dist-packages/tf_encrypted/operations/secure_random/secure_random_module_tf_1.14.0.so'
W0813 08:46:34.211576 140520788572032 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/tf_encrypted/session.py:26: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

0it [00:00, ?it/s]

Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ../data/cifar-10-python.tar.gz

170500096it [00:04, 40609204.86it/s]

---------------------------------------------------------------------------

PureTorchTensorFoundError                 Traceback (most recent call last)

/content/PySyft/syft/frameworks/torch/tensors/interpreters/native.py in handle_func_command(cls, command)
300             new_args, new_kwargs, new_type, args_type = syft.frameworks.torch.hook_args.unwrap_args_from_function(
--> 301                 cmd, args, kwargs, return_args_type=True
302             )

16 frames

PureTorchTensorFoundError:


During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in batch_norm(input, running_mean, running_var, weight, bias, training, momentum, eps)
1695     return torch.batch_norm(
1696         input, weight, bias, running_mean, running_var,
-> 1697         training, momentum, eps, torch.backends.cudnn.enabled
1698     )
1699

RuntimeError: running_mean should contain 3 elements not 32

# Fixed code
def module_get_(nn_self):
    """overloads torch.nn instances with get method so that parameters could be sent back to owner"""
    for element_iter in tensor_iterator(nn_self):
        for p in element_iter():
            p.get_()

    if isinstance(nn_self.forward, Plan):
        nn_self.forward.get()

    return nn_self
# Buggy code
def module_share_(nn_self, *args, **kwargs):
    """Overloads fix_precision for torch.nn.Module."""
    # TODO: add .data and .grad to syft tensors
    if module_is_missing_grad(nn_self):
        create_grad_objects(nn_self)

    for p in nn_self.parameters():
        p.share_(*args, **kwargs)

    return nn_self


# Traceback (PureTorchTensorFoundError)
WARNING: Logging before flag parsing goes to stderr.
W0813 08:46:34.190028 140520788572032 secure_random.py:26] Falling back to insecure randomness since the required custom op could not be found for the installed version of TensorFlow. Fix this by compiling custom ops. Missing file was '/usr/local/lib/python3.6/dist-packages/tf_encrypted/operations/secure_random/secure_random_module_tf_1.14.0.so'
W0813 08:46:34.211576 140520788572032 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/tf_encrypted/session.py:26: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

0it [00:00, ?it/s]

Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ../data/cifar-10-python.tar.gz

170500096it [00:04, 40609204.86it/s]

---------------------------------------------------------------------------

PureTorchTensorFoundError                 Traceback (most recent call last)

/content/PySyft/syft/frameworks/torch/tensors/interpreters/native.py in handle_func_command(cls, command)
300             new_args, new_kwargs, new_type, args_type = syft.frameworks.torch.hook_args.unwrap_args_from_function(
--> 301                 cmd, args, kwargs, return_args_type=True
302             )

16 frames

PureTorchTensorFoundError:


During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in batch_norm(input, running_mean, running_var, weight, bias, training, momentum, eps)
1695     return torch.batch_norm(
1696         input, weight, bias, running_mean, running_var,
-> 1697         training, momentum, eps, torch.backends.cudnn.enabled
1698     )
1699

RuntimeError: running_mean should contain 3 elements not 32

# Fixed code
def module_share_(nn_self, *args, **kwargs):
    """Overloads fix_precision for torch.nn.Module."""
    if module_is_missing_grad(nn_self):
        create_grad_objects(nn_self)

    for element_iter in tensor_iterator(nn_self):
        for p in element_iter():
            p.share_(*args, **kwargs)

    return nn_self
# Buggy code
def module_fix_precision_(nn_self, *args, **kwargs):
    """Overloads fix_precision for torch.nn.Module."""
    if module_is_missing_grad(nn_self):
        create_grad_objects(nn_self)

    for p in nn_self.parameters():
        p.fix_precision_(*args, **kwargs)

    return nn_self


# Traceback (PureTorchTensorFoundError)
WARNING: Logging before flag parsing goes to stderr.
W0813 08:46:34.190028 140520788572032 secure_random.py:26] Falling back to insecure randomness since the required custom op could not be found for the installed version of TensorFlow. Fix this by compiling custom ops. Missing file was '/usr/local/lib/python3.6/dist-packages/tf_encrypted/operations/secure_random/secure_random_module_tf_1.14.0.so'
W0813 08:46:34.211576 140520788572032 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/tf_encrypted/session.py:26: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

0it [00:00, ?it/s]

Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ../data/cifar-10-python.tar.gz

170500096it [00:04, 40609204.86it/s]

---------------------------------------------------------------------------

PureTorchTensorFoundError                 Traceback (most recent call last)

/content/PySyft/syft/frameworks/torch/tensors/interpreters/native.py in handle_func_command(cls, command)
300             new_args, new_kwargs, new_type, args_type = syft.frameworks.torch.hook_args.unwrap_args_from_function(
--> 301                 cmd, args, kwargs, return_args_type=True
302             )

16 frames

PureTorchTensorFoundError:


During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in batch_norm(input, running_mean, running_var, weight, bias, training, momentum, eps)
1695     return torch.batch_norm(
1696         input, weight, bias, running_mean, running_var,
-> 1697         training, momentum, eps, torch.backends.cudnn.enabled
1698     )
1699

RuntimeError: running_mean should contain 3 elements not 32

# Fixed code
def module_fix_precision_(nn_self, *args, **kwargs):
    """Overloads fix_precision for torch.nn.Module."""
    if module_is_missing_grad(nn_self):
        create_grad_objects(nn_self)

    for element_iter in tensor_iterator(nn_self):
        for p in element_iter():
            p.fix_precision_(*args, **kwargs)

    return nn_self
# Buggy code
def module_float_precision_(nn_self):
    """Overloads float_precision for torch.nn.Module, convert fix_precision
    parameters to normal float parameters"""
    # TODO: add .data and .grad to syft tensors
    # if module_is_missing_grad(nn_self):
    #    create_grad_objects(nn_self)

    for p in nn_self.parameters():
        p.float_precision_()

    return nn_self


# Traceback (PureTorchTensorFoundError)
WARNING: Logging before flag parsing goes to stderr.
W0813 08:46:34.190028 140520788572032 secure_random.py:26] Falling back to insecure randomness since the required custom op could not be found for the installed version of TensorFlow. Fix this by compiling custom ops. Missing file was '/usr/local/lib/python3.6/dist-packages/tf_encrypted/operations/secure_random/secure_random_module_tf_1.14.0.so'
W0813 08:46:34.211576 140520788572032 deprecation_wrapper.py:119] From /usr/local/lib/python3.6/dist-packages/tf_encrypted/session.py:26: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

0it [00:00, ?it/s]

Downloading https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz to ../data/cifar-10-python.tar.gz

170500096it [00:04, 40609204.86it/s]

---------------------------------------------------------------------------

PureTorchTensorFoundError                 Traceback (most recent call last)

/content/PySyft/syft/frameworks/torch/tensors/interpreters/native.py in handle_func_command(cls, command)
300             new_args, new_kwargs, new_type, args_type = syft.frameworks.torch.hook_args.unwrap_args_from_function(
--> 301                 cmd, args, kwargs, return_args_type=True
302             )

16 frames

PureTorchTensorFoundError:


During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in batch_norm(input, running_mean, running_var, weight, bias, training, momentum, eps)
1695     return torch.batch_norm(
1696         input, weight, bias, running_mean, running_var,
-> 1697         training, momentum, eps, torch.backends.cudnn.enabled
1698     )
1699

RuntimeError: running_mean should contain 3 elements not 32

# Fixed code
def module_float_precision_(nn_self):
    """Overloads float_precision for torch.nn.Module, convert fix_precision
    parameters to normal float parameters"""
    # TODO: add .data and .grad to syft tensors
    # if module_is_missing_grad(nn_self):
    #    create_grad_objects(nn_self)

    for element_iter in tensor_iterator(nn_self):
        for p in element_iter():
            p.float_precision_()

    return nn_self
# Buggy code
def _var_to_pointer(self, var, hook_self):
    if var.grad is not None:
        self._var_to_pointer(var.grad, hook_self)

    var.data.old_set_(var.data.__class__(0))
    self.local_worker.register_object(
        hook_self.local_worker,
        obj=var.data,
        id=var.data.id,
        owners=var.owners,
        is_pointer=True,
    )
    return var


# Traceback (RuntimeError)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-14-4207de4e45fd> in <module>()
10 loss.backward()
11
---> 12 model.send_(remote)

/Users/atrask/anaconda/lib/python3.6/site-packages/syft-0.1.0-py3.6.egg/syft/core/hooks.py in send_(self, workers)
907                                                    owners=self.owners, is_pointer=True)
908
--> 909             return hook_self._var_to_pointer(self, hook_self)
910
911         setattr(torch.autograd.variable.Variable, 'send_', send_)

/Users/atrask/anaconda/lib/python3.6/site-packages/syft-0.1.0-py3.6.egg/syft/core/hooks.py in _var_to_pointer(self, var, hook_self)
982         print("_var_to_pointer:" + str(var.data.id))
983         if var.grad is not None:
--> 984             self._var_to_pointer(var.grad, hook_self)
985
986         var.data.old_set_(var.data.__class__(0))

/Users/atrask/anaconda/lib/python3.6/site-packages/syft-0.1.0-py3.6.egg/syft/core/hooks.py in _var_to_pointer(self, var, hook_self)
989                                           id=var.data.id,
990                                           owners=var.owners,
--> 991                                           is_pointer=True)
992         return var
993

/Users/atrask/anaconda/lib/python3.6/site-packages/syft-0.1.0-py3.6.egg/syft/core/workers.py in register_object(self, worker, obj, force_attach_to_worker, temporary, **kwargs)
508             raise RuntimeError(
509                 'Invalid registry: is_pointer is {} but owners is {} on tensor {}'.format(
--> 510                     obj.is_pointer, obj.owners, obj.id))
511         # print("setting object:" + str(obj.id))
512         self.set_obj(obj.id, obj, force=force_attach_to_worker, tmp=temporary)

RuntimeError: Invalid registry: is_pointer is True but owners is [0] on tensor 2841986768

# Fixed code
def _var_to_pointer(self, var, hook_self):
    # recursively calls var_to_pointer in a depth first fashion
    # only recursive through variables (ignores .data)
    if var.grad is not None:
        self._var_to_pointer(var.grad, hook_self)

    # deletes local data (because now it's a pointer to remote data)
    var.data.old_set_(var.data.__class__(0))

    return var
# Buggy code
def read(self):
    return self


# Traceback (UnicodeEncodeError)
$ rst2pdf test.rst -e preprocess -v
[INFO] createpdf.py:1578 Importing extension module 'vectorpdf'
[INFO] createpdf.py:1578 Importing extension module 'preprocess'
Traceback (most recent call last):
File "/Users/rob/.pyenv/versions/rst2pdf-2/bin/rst2pdf", line 11, in <module>
load_entry_point('rst2pdf', 'console_scripts', 'rst2pdf')()
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/createpdf.py", line 1461, in main
add_extensions(options)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/createpdf.py", line 1592, in add_extensions
module.install(createpdf, options)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/extensions/preprocess_r2p.py", line 367, in install
data = Preprocess(options.infile)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/extensions/preprocess_r2p.py", line 153, in __init__
self.sourcef = DummyFile(source)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 44-46: ordinal not in range(128)

# Fixed code
def read(self):
    return self._str
# Buggy code
def get_family(query):
    data = os.popen('fc-match "%s"' % query, "r").read()
    for line in data.splitlines():
        line = line.strip()
        if not line:
            continue
        fname, family, _, variant = line.split('"')[:4]
        family = family.replace('"', "")
        if family:
            return family
    return None


# Traceback (UnicodeDecodeError)
$ cd doc
$ rst2pdf manual.rst --custom-cover=assets/cover.tmpl -o output/pdf/manual.pdf -s assets/manual.style -b1
Traceback (most recent call last):
File "/Users/rob/.pyenv/versions/rst2pdf/bin/rst2pdf", line 11, in <module>
load_entry_point('rst2pdf', 'console_scripts', 'rst2pdf')()
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/createpdf.py", line 1506, in main
strip_elements_with_classes=options.strip_elements_with_classes,
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/createpdf.py", line 184, in __init__
self.loadStyles(stylesheets)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/createpdf.py", line 288, in loadStyles
def_dpi=self.def_dpi)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/styles.py", line 358, in __init__
fontList = findfonts.autoEmbed(style[key])
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/findfonts.py", line 316, in autoEmbed
variants = findTTFont(fname)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/findfonts.py", line 221, in findTTFont
return get_variants(family)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/findfonts.py", line 204, in get_variants
get_fname(family + ":style=Roman"),
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/findfonts.py", line 198, in get_fname
if line.startswith("file: "):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 36: ordinal not in range(128)

# Fixed code
def get_family(query):
    data = subprocess.check_output(["fc-match", query])
    if six.PY2:
        data = data.decode("UTF-8")
    for line in data.splitlines():
        line = line.strip()
        if not line:
            continue
        fname, family, _, variant = line.split('"')[:4]
        family = family.replace('"', "")
        if family:
            return family
    return None
# Buggy code
def get_fname(query):
    data = os.popen('fc-match -v "%s"' % query, "r").read()
    for line in data.splitlines():
        line = line.strip()
        if line.startswith("file: "):
            return line.split('"')[1]
    return None


# Traceback (UnicodeDecodeError)
$ cd doc
$ rst2pdf manual.rst --custom-cover=assets/cover.tmpl -o output/pdf/manual.pdf -s assets/manual.style -b1
Traceback (most recent call last):
File "/Users/rob/.pyenv/versions/rst2pdf/bin/rst2pdf", line 11, in <module>
load_entry_point('rst2pdf', 'console_scripts', 'rst2pdf')()
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/createpdf.py", line 1506, in main
strip_elements_with_classes=options.strip_elements_with_classes,
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/createpdf.py", line 184, in __init__
self.loadStyles(stylesheets)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/createpdf.py", line 288, in loadStyles
def_dpi=self.def_dpi)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/styles.py", line 358, in __init__
fontList = findfonts.autoEmbed(style[key])
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/findfonts.py", line 316, in autoEmbed
variants = findTTFont(fname)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/findfonts.py", line 221, in findTTFont
return get_variants(family)
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/findfonts.py", line 204, in get_variants
get_fname(family + ":style=Roman"),
File "/Users/rob/Projects/python/rst2pdf/rst2pdf/findfonts.py", line 198, in get_fname
if line.startswith("file: "):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 36: ordinal not in range(128)

# Fixed code
def get_fname(query):
    data = subprocess.check_output(["fc-match", "-v", query])
    if six.PY2:
        data = data.decode("UTF-8")
    for line in data.splitlines():
        line = line.strip()
        if line.startswith("file: "):
            return line.split('"')[1]
    return None
# Buggy code
def get_pre_post(self, client, node, replaceEnt):
    pre = ""
    if node["ids"][0] not in client.targets:
        pre = '<a name="%s"/>' % node["ids"][0]
        client.targets.append(node["ids"][0])
    return pre, ""


# Traceback (IndexError)
Traceback (most recent call last):
File "/usr/bin/rst2pdf", line 9, in <module>
load_entry_point('rst2pdf===0.93.dev-r0', 'console_scripts', 'rst2pdf')()
File "/usr/lib/python2.7/site-packages/rst2pdf/createpdf.py", line 1495, in main
compressed=options.compressed)
File "/usr/lib/python2.7/site-packages/rst2pdf/createpdf.py", line 561, in createPdf
elements = self.gen_elements(self.doctree)
File "/usr/lib/python2.7/site-packages/rst2pdf/basenodehandler.py", line 250, in elemdispatch
elements = self.getelements(client, node, style)
File "/usr/lib/python2.7/site-packages/rst2pdf/basenodehandler.py", line 225, in getelements
elements = self.gather_elements(client, node, style)
File "/usr/lib/python2.7/site-packages/rst2pdf/basenodehandler.py", line 205, in gather_elements
return client.gather_elements(node, style=style)
File "/usr/lib/python2.7/site-packages/rst2pdf/createpdf.py", line 390, in gather_elements
r.extend(self.gen_elements(n, style=style))
File "/usr/lib/python2.7/site-packages/rst2pdf/basenodehandler.py", line 250, in elemdispatch
elements = self.getelements(client, node, style)
File "/usr/lib/python2.7/site-packages/rst2pdf/basenodehandler.py", line 225, in getelements
elements = self.gather_elements(client, node, style)
File "/usr/lib/python2.7/site-packages/rst2pdf/genelements.py", line 188, in gather_elements
return [Paragraph(client.gen_pdftext(node), style)]
File "/usr/lib/python2.7/site-packages/rst2pdf/basenodehandler.py", line 280, in textdispatch
text = self.get_text(client, node, replaceEnt)
File "/usr/lib/python2.7/site-packages/rst2pdf/basenodehandler.py", line 266, in get_text
return client.gather_pdftext(node)
File "/usr/lib/python2.7/site-packages/rst2pdf/createpdf.py", line 380, in gather_pdftext
for n in node.children])
File "/usr/lib/python2.7/site-packages/rst2pdf/basenodehandler.py", line 279, in textdispatch
pre, post = self.get_pre_post(client, node, replaceEnt)
File "/usr/lib/python2.7/site-packages/rst2pdf/genpdftext.py", line 225, in get_pre_post
if node['ids'][0] not in client.targets:
IndexError: list index out of range

# Fixed code
def get_pre_post(self, client, node, replaceEnt):
    pre = ""
    if node["ids"]:
        if node["ids"][0] not in client.targets:
            pre = '<a name="%s"/>' % node["ids"][0]
            client.targets.append(node["ids"][0])
    else:
        pre = '<a name="%s"/>' % node["refuri"]
        client.targets.append(node["refuri"])
    return pre, ""
# Buggy code
def __init__(
    self,
    input_cache_dir: Text,
    output_cache_dir: Text,
    analyze_data_list: List[_Dataset],
    typespecs: Mapping[Text, tf.TypeSpec],
    preprocessing_fn: Any,
    cache_source: beam.PTransform,
):
    # pyformat: enable
    self._input_cache_dir = input_cache_dir
    self._output_cache_dir = output_cache_dir
    self._analyze_data_list = analyze_data_list
    self._feature_spec_or_typespec = typespecs
    self._preprocessing_fn = preprocessing_fn
    self._cache_source = cache_source


# Traceback (IndexError)
RuntimeError: Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/apache_beam/runners/worker/sdk_worker.py", line 312, in get
processor = self.cached_bundle_processors[bundle_descriptor_id].pop()
IndexError: pop from empty list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/apache_beam/internal/pickler.py", line 250, in dumps
s = dill.dumps(o)
...

File "/usr/local/lib/python3.6/dist-packages/apache_beam/internal/pickler.py", line 77, in _is_nested_class
and cls.__name__ not in sys.modules[cls.__module__].__dict__)
KeyError: 'user_module'

During handling of the above exception, another exception occurred:

# Fixed code
def __init__(
    self,
    input_cache_dir: Text,
    output_cache_dir: Text,
    analyze_data_list: List[_Dataset],
    typespecs: Mapping[Text, tf.TypeSpec],
    preprocessing_fn: Any,
    cache_source: beam.PTransform,
    force_tf_compat_v1: bool,
):
    # pyformat: enable
    self._input_cache_dir = input_cache_dir
    self._output_cache_dir = output_cache_dir
    self._analyze_data_list = analyze_data_list
    self._feature_spec_or_typespec = typespecs
    self._preprocessing_fn = preprocessing_fn
    self._cache_source = cache_source
    self._force_tf_compat_v1 = force_tf_compat_v1
# Buggy code
def import_func_from_source(source_path: Text, fn_name: Text) -> Callable:  # pylint: disable=g-bare-generic
    """Imports a function from a module provided as source file."""

    # If module path is not local, download to local file-system first,
    # because importlib can't import from GCS
    source_path = io_utils.ensure_local(source_path)

    try:
        if six.PY2:
            import imp  # pylint: disable=g-import-not-at-top

            try:
                user_module = imp.load_source("user_module", source_path)
                return getattr(user_module, fn_name)
            except IOError:
                raise

        else:
            loader = importlib.machinery.SourceFileLoader(
                fullname="user_module",
                path=source_path,
            )
            user_module = types.ModuleType(loader.name)
            loader.exec_module(user_module)
            return getattr(user_module, fn_name)

    except IOError:
        raise ImportError(
            "{} in {} not found in import_func_from_source()".format(
                fn_name, source_path
            )
        )


# Traceback (IndexError)
RuntimeError: Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/apache_beam/runners/worker/sdk_worker.py", line 312, in get
processor = self.cached_bundle_processors[bundle_descriptor_id].pop()
IndexError: pop from empty list

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/apache_beam/internal/pickler.py", line 250, in dumps
s = dill.dumps(o)
...

File "/usr/local/lib/python3.6/dist-packages/apache_beam/internal/pickler.py", line 77, in _is_nested_class
and cls.__name__ not in sys.modules[cls.__module__].__dict__)
KeyError: 'user_module'

During handling of the above exception, another exception occurred:

# Fixed code
def import_func_from_source(source_path: Text, fn_name: Text) -> Callable:  # pylint: disable=g-bare-generic
    """Imports a function from a module provided as source file."""

    # If module path is not local, download to local file-system first,
    # because importlib can't import from GCS
    source_path = io_utils.ensure_local(source_path)

    try:
        loader = importlib.machinery.SourceFileLoader(
            fullname="user_module",
            path=source_path,
        )
        spec = importlib.util.spec_from_loader(loader.name, loader, origin=source_path)
        module = importlib.util.module_from_spec(spec)
        sys.modules[loader.name] = module
        loader.exec_module(module)
        return getattr(module, fn_name)

    except IOError:
        raise ImportError(
            "{} in {} not found in import_func_from_source()".format(
                fn_name, source_path
            )
        )
# Buggy code
def __str__(self) -> str:
    return "Undefined field. Filed cannot be None."


# Traceback (KeyError)
from mimesis.schema import Field, Schema
_ = Field('en')
_('choice', items=[1,2,3])
Traceback (most recent call last):
File "C:\dev\fakemimesis\.pyenv\lib\site-packages\mimesis\schema.py", line 100, in __call__
result = self._table[name](**kwargs)
KeyError: 'choice'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
_('choice', items=[1,2,3])
File "C:\dev\fakemimesis\.pyenv\lib\site-packages\mimesis\schema.py", line 105, in __call__
raise UnsupportedField(name)
mimesis.exceptions.UnsupportedField: Field «choice» is not supported.


# Fixed code
def __str__(self) -> str:
    return "Unacceptable field format, use **provider.method**."
# Buggy code
def tail_parser(tails: str, obj: Any) -> Any:
    """Return method from end of tail.

    :param tails: Tail string
    :param obj: Search tail from this object
    :return last tailed method
    """
    first, second = tails.split(".", 1)
    if hasattr(obj, first):
        attr = getattr(obj, first)
        if "." in second:
            return tail_parser(attr, second)
        else:
            return getattr(attr, second)


# Traceback (KeyError)
from mimesis.schema import Field, Schema
_ = Field('en')
_('choice', items=[1,2,3])
Traceback (most recent call last):
File "C:\dev\fakemimesis\.pyenv\lib\site-packages\mimesis\schema.py", line 100, in __call__
result = self._table[name](**kwargs)
KeyError: 'choice'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
_('choice', items=[1,2,3])
File "C:\dev\fakemimesis\.pyenv\lib\site-packages\mimesis\schema.py", line 105, in __call__
raise UnsupportedField(name)
mimesis.exceptions.UnsupportedField: Field «choice» is not supported.


# Fixed code
def tail_parser(tails: str, obj: Any) -> Any:
    """Return method from end of tail.

    :param tails: Tail string
    :param obj: Search tail from this object
    :return last tailed method
    """
    provider_name, method_name = tails.split(".", 1)

    if "." in method_name:
        raise UnacceptableField()

    attr = getattr(obj, provider_name)
    if attr is not None:
        return getattr(attr, method_name)
# Buggy code
def _bind_to_schema(self, field_name, schema):
    super()._bind_to_schema(field_name, schema)
    self.format = (
        self.format
        or getattr(schema.opts, self.SCHEMA_OPTS_VAR_NAME)
        or self.DEFAULT_FORMAT
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "test-mm.py", line 8, in <module>
s = MySchema()
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/schema.py", line 383, in __init__
self.fields = self._init_fields()
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/schema.py", line 913, in _init_fields
self._bind_field(field_name, field_obj)
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/schema.py", line 969, in _bind_field
field_obj._bind_to_schema(field_name, self)
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/fields.py", line 636, in _bind_to_schema
self.inner._bind_to_schema(field_name, self)
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/fields.py", line 1117, in _bind_to_schema
or getattr(schema.opts, self.SCHEMA_OPTS_VAR_NAME)
AttributeError: 'List' object has no attribute 'opts'

# Fixed code
def _bind_to_schema(self, field_name, schema):
    super()._bind_to_schema(field_name, schema)
    self.format = (
        self.format
        or getattr(self.root.opts, self.SCHEMA_OPTS_VAR_NAME)
        or self.DEFAULT_FORMAT
    )
# Buggy code
def _deserialize(self, value, attr, data):
    if not value:  # Falsy values, e.g. '', None, [] are not valid
        raise self.fail("invalid", obj_type=self.OBJ_TYPE)
    data_format = self.format or self.DEFAULT_FORMAT
    func = self.DESERIALIZATION_FUNCS.get(data_format)
    if func:
        try:
            return func(value)
        except (TypeError, AttributeError, ValueError):
            raise self.fail("invalid", obj_type=self.OBJ_TYPE)
    elif data_format:
        try:
            return dt.datetime.strptime(value, data_format)
        except (TypeError, AttributeError, ValueError):
            raise self.fail("invalid", obj_type=self.OBJ_TYPE)
    elif utils.dateutil_available:
        try:
            parsed = utils.from_datestring(value)
            return self._create_data_object_from_parsed_value(parsed)
        except (TypeError, ValueError):
            raise self.fail("invalid", obj_type=self.OBJ_TYPE)
    else:
        warnings.warn(
            "It is recommended that you install python-dateutil "
            "for improved datetime deserialization.",
        )
        raise self.fail("invalid", obj_type=self.OBJ_TYPE)


# Traceback (marshmallow.exceptions.ValidationError)
import marshmallow as ma
f = ma.fields.DateTime()
f.deserialize('2018/03/26')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "marshmallow/fields.py", line 261, in deserialize
output = self._deserialize(value, attr, data)
File "marshmallow/fields.py", line 929, in _deserialize
raise self.fail('invalid')
File "marshmallow/fields.py", line 216, in fail
raise ValidationError(msg)
marshmallow.exceptions.ValidationError: Not a valid datetime.

# Fixed code
def _deserialize(self, value, attr, data):
    if not value:  # Falsy values, e.g. '', None, [] are not valid
        raise self.fail("invalid", obj_type=self.OBJ_TYPE)
    data_format = self.format or self.DEFAULT_FORMAT
    func = self.DESERIALIZATION_FUNCS.get(data_format)
    if func:
        try:
            return func(value)
        except (TypeError, AttributeError, ValueError):
            raise self.fail("invalid", obj_type=self.OBJ_TYPE)
    else:
        try:
            return dt.datetime.strptime(value, data_format)
        except (TypeError, AttributeError, ValueError):
            raise self.fail("invalid", obj_type=self.OBJ_TYPE)
# Buggy code
def __init__(
    self,
    contigs_db_path,
    sources=set([]),
    split_names_of_interest=set([]),
    init=True,
    run=run,
    progress=progress,
):
    self.run = run
    self.progress = progress

    if not isinstance(sources, type(set([]))):
        raise ConfigError("'sources' variable has to be a set instance.")

    if not isinstance(split_names_of_interest, type(set([]))):
        raise ConfigError(
            "'split_names_of_interest' variable has to be a set instance."
        )

    self.sources = set([s for s in sources if s])
    self.hmm_hits = {}
    self.hmm_hits_info = {}
    self.hmm_hits_splits = {}
    self.contig_sequences = {}
    self.aa_sequences = {}
    self.genes_in_contigs = {}
    self.splits_in_contigs = {}

    if contigs_db_path:
        self.init_dicts(contigs_db_path, split_names_of_interest)
        self.initialized = True
    else:
        self.initialized = False


# Traceback (KeyError)
[09 Dec 20 09:32:25 Summarizing 104 of 159: 'Bin_3_32'] Creating the FASTA file ...                                      ETA: 1m18sTraceback (most recent call last):
File "/workdir/lab_envs/anvio/bin/anvi-summarize", line 118, in <module>
main(args)
File "/workdir/lab_envs/anvio/bin/anvi-summarize", line 63, in main
summary.process()
File "/workdir/lab_envs/anvio/lib/python3.6/site-packages/anvio/summarizer.py", line 874, in process
self.summary['collection'][bin_id] = bin.create()
File "/workdir/lab_envs/anvio/lib/python3.6/site-packages/anvio/summarizer.py", line 1273, in create
self.store_sequences_for_hmm_hits()
File "/workdir/lab_envs/anvio/lib/python3.6/site-packages/anvio/summarizer.py", line 1533, in store_sequences_for_hmm_hits
hmm_sequences_dict = s.get_sequences_dict_for_hmm_hits_in_splits({self.bin_id: self.split_names})
File "/workdir/lab_envs/anvio/lib/python3.6/site-packages/anvio/hmmops.py", line 336, in get_sequences_dict_for_hmm_hits_in_splits
hmm_hit = self.hmm_hits[split_entry['hmm_hit_entry_id']]
KeyError: 17702

# Fixed code
def __init__(
    self,
    contigs_db_path,
    sources=set([]),
    split_names_of_interest=set([]),
    init=True,
    run=run,
    progress=progress,
    bin_name=None,
):
    self.run = run
    self.progress = progress

    if not isinstance(sources, type(set([]))):
        raise ConfigError("'sources' variable has to be a set instance.")

    if not isinstance(split_names_of_interest, type(set([]))):
        raise ConfigError(
            "'split_names_of_interest' variable has to be a set instance."
        )

    self.bin_name = bin_name  # this is only relevant for some output messages
    self.sources = set([s for s in sources if s])
    self.hmm_hits = {}
    self.hmm_hits_info = {}
    self.hmm_hits_splits = {}
    self.contig_sequences = {}
    self.aa_sequences = {}
    self.genes_in_contigs = {}
    self.splits_in_contigs = {}

    if contigs_db_path:
        self.init_dicts(contigs_db_path, split_names_of_interest)
        self.initialized = True
    else:
        self.initialized = False
# Buggy code
def share_project(request, userdb, response):
    set_default_headers(response)
    return json.dumps(
        share=userdb.create_view(
            get_user(request, userdb, response),
            request.forms.get("name"),
            request.forms.get("project"),
            request.forms.get("public"),
        )
    )


# Traceback (NameError)
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/bottle.py", line 1732, in wrapper
rv = callback(*a, **ka)
File "/Users/meren/Desktop/MBL/anvio/bin/anvi-server", line 169, in share_project
return multiroutes.share_project(request, userdb, response)
File "/Users/meren/Desktop/MBL/anvio/anvio/bottleroutes_multi.py", line 124, in share_project
return json.dumps(share = userdb.create_view(get_user(request, userdb, response), request.forms.get('name'), request.forms.get('project'), request.forms.get('public')))
File "/Users/meren/Desktop/MBL/anvio/anvio/usermgmt.py", line 670, in create_view
p = (pname, login)
NameError: global name 'login' is not defined

# Fixed code
def share_project(request, userdb, response):
    set_default_headers(response)
    return json.dumps(
        userdb.create_view(
            get_user(request, userdb, response),
            request.forms.get("name"),
            request.forms.get("project"),
            request.forms.get("public"),
        )
    )
# Buggy code
async def get(self, key):
    """Get data from Redis for a given key.

    Args:
        key (string): The key to lookup in the database.

    Returns:
        object or None: The data object stored for that key, or None if no
                        object found for that key.

    """
    if self.client:
        _LOGGER.debug(_("Getting %s from Redis."), key)
        data = await self.client.execute("GET", key)

        if data:
            return json.loads(data, encoding=JSONDecoder)

        return None


# Traceback (TypeError)
notrexroof_1  | DEBUG opsdroid.memory: Putting seen to memory.
notrexroof_1  | DEBUG opsdroid.database.redis: Putting seen into Redis.
notrexroof_1  | ERROR opsdroid.core: Exception when running skill 'seen'.
notrexroof_1  | Traceback (most recent call last):
notrexroof_1  |   File "/usr/local/lib/python3.8/site-packages/opsdroid/core.py", line 427, in run_skill
notrexroof_1  |     return await skill(self, config, event)
notrexroof_1  |   File "/root/.local/share/opsdroid/opsdroid-modules/skill/seen/__init__.py", line 16, in last_seen
notrexroof_1  |     await message.respond("I last saw {} {}".format(name, human(seen[name], precision=1)))
notrexroof_1  |   File "/root/.local/share/opsdroid/site-packages/ago.py", line 55, in human
notrexroof_1  |     delta = get_delta_from_subject(subject)
notrexroof_1  |   File "/root/.local/share/opsdroid/site-packages/ago.py", line 16, in get_delta_from_subject
notrexroof_1  |     subject = float(subject)
notrexroof_1  | TypeError: float() argument must be a string or a number, not 'dict'

# Fixed code
async def get(self, key):
    """Get data from Redis for a given key.

    Args:
        key (string): The key to lookup in the database.

    Returns:
        object or None: The data object stored for that key, or None if no
                        object found for that key.

    """
    if self.client:
        _LOGGER.debug(_("Getting %s from Redis."), key)
        data = await self.client.execute("GET", key)

        if data:
            return json.loads(data, object_hook=JSONDecoder())

        return None