gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _get_full_key(self, key: Union[str, Enum, int, None]) -> str:
    parent = self._get_parent()
    if parent is None:
        if self._metadata.key is None:
            return ""
        else:
            return str(self._metadata.key)
    else:
        return parent._get_full_key(self._metadata.key)


# Traceback (KeyError)
del cfg["FOO"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jasha10/omegaconf/omegaconf/dictconfig.py", line 405, in __delitem__
del self.__dict__["_content"][key]
KeyError: 'FOO'

# Fixed code
def _get_full_key(self, key: Optional[Union[DictKeyType, int]]) -> str:
    parent = self._get_parent()
    if parent is None:
        if self._metadata.key is None:
            return ""
        else:
            return str(self._metadata.key)
    else:
        return parent._get_full_key(self._metadata.key)
# Buggy code
def validate_and_convert_to_enum(enum_type: Type[Enum], value: Any) -> Optional[Enum]:
    if value is None:
        return None

    if not isinstance(value, (str, int)) and not isinstance(value, enum_type):
        raise ValidationError(
            f"Value $VALUE ($VALUE_TYPE) is not a valid input for {enum_type}"
        )

    if isinstance(value, enum_type):
        return value

    try:
        if isinstance(value, (float, bool)):
            raise ValueError

        if isinstance(value, int):
            return enum_type(value)

        if isinstance(value, str):
            prefix = f"{enum_type.__name__}."
            if value.startswith(prefix):
                value = value[len(prefix) :]
            return enum_type[value]

        assert False

    except (ValueError, KeyError) as e:
        valid = ", ".join([x for x in enum_type.__members__.keys()])
        raise ValidationError(
            f"Invalid value '$VALUE', expected one of [{valid}]"
        ).with_traceback(sys.exc_info()[2]) from e


# Traceback (KeyError)
del cfg["FOO"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jasha10/omegaconf/omegaconf/dictconfig.py", line 405, in __delitem__
del self.__dict__["_content"][key]
KeyError: 'FOO'

# Fixed code
def validate_and_convert_to_enum(
    enum_type: Type[Enum], value: Any, allow_none: bool = True
) -> Optional[Enum]:
    if allow_none and value is None:
        return None

    if not isinstance(value, (str, int)) and not isinstance(value, enum_type):
        raise ValidationError(
            f"Value $VALUE ($VALUE_TYPE) is not a valid input for {enum_type}"
        )

    if isinstance(value, enum_type):
        return value

    try:
        if isinstance(value, (float, bool)):
            raise ValueError

        if isinstance(value, int):
            return enum_type(value)

        if isinstance(value, str):
            prefix = f"{enum_type.__name__}."
            if value.startswith(prefix):
                value = value[len(prefix) :]
            return enum_type[value]

        assert False

    except (ValueError, KeyError) as e:
        valid = ", ".join([x for x in enum_type.__members__.keys()])
        raise ValidationError(
            f"Invalid value '$VALUE', expected one of [{valid}]"
        ).with_traceback(sys.exc_info()[2]) from e
# Buggy code
def to_container(
    cfg: Any,
    *,
    resolve: bool = False,
    enum_to_str: bool = False,
    exclude_structured_configs: bool = False,
) -> Union[Dict[DictKeyType, Any], List[Any], None, str]:
    """
    Resursively converts an OmegaConf config to a primitive container (dict or list).
    :param cfg: the config to convert
    :param resolve: True to resolve all values
    :param enum_to_str: True to convert Enum values to strings
    :param exclude_structured_configs: If True, do not convert Structured Configs
           (DictConfigs backed by a dataclass)
    :return: A dict or a list representing this config as a primitive container.
    """
    assert isinstance(cfg, Container)
    # noinspection PyProtectedMember
    return BaseContainer._to_content(
        cfg,
        resolve=resolve,
        enum_to_str=enum_to_str,
        exclude_structured_configs=exclude_structured_configs,
    )


# Traceback (AssertionError)
Traceback (most recent call last):
File "cluster.py", line 24, in start_job
OmegaConf.to_container(cfg, resolve=True)
AssertionError

Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.

# Fixed code
def to_container(
    cfg: Any,
    *,
    resolve: bool = False,
    enum_to_str: bool = False,
    exclude_structured_configs: bool = False,
) -> Union[Dict[DictKeyType, Any], List[Any], None, str]:
    """
    Resursively converts an OmegaConf config to a primitive container (dict or list).
    :param cfg: the config to convert
    :param resolve: True to resolve all values
    :param enum_to_str: True to convert Enum values to strings
    :param exclude_structured_configs: If True, do not convert Structured Configs
           (DictConfigs backed by a dataclass)
    :return: A dict or a list representing this config as a primitive container.
    """
    if not OmegaConf.is_config(cfg):
        raise ValueError(
            f"Input cfg is not an OmegaConf config object ({type_str(type(cfg))})"
        )

    return BaseContainer._to_content(
        cfg,
        resolve=resolve,
        enum_to_str=enum_to_str,
        exclude_structured_configs=exclude_structured_configs,
    )
# Buggy code
def _is_missing(self) -> bool:
    try:
        self._dereference_node(throw_on_missing=True)
        return False
    except MissingMandatoryValue:
        ret = True

    assert isinstance(ret, bool)
    return ret


# Traceback (omegaconf.errors.ConfigKeyError)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/omegaconf.py", line 321, in merge
target.merge_with(*others[1:])
File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/basecontainer.py", line 327, in merge_with
self._format_and_raise(key=None, value=None, cause=e)
File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/base.py", line 101, in _format_and_raise
type_override=type_override,
File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/_utils.py", line 675, in format_and_raise
_raise(ex, cause)
File "/private/home/abaevski/.conda/envs/fairseq-fp16-20200821/lib/python3.6/site-packages/omegaconf/_utils.py", line 591, in _raise
raise ex  # set end OC_CAUSE=1 for full backtrace
omegaconf.errors.ConfigKeyError: str interpolation key 'optimization.lr' not found
full_key:
reference_type=Any
object_type=test_class

# Fixed code
def _is_missing(self) -> bool:
    try:
        self._dereference_node(throw_on_resolution_failure=False, throw_on_missing=True)
        return False
    except MissingMandatoryValue:
        ret = True

    assert isinstance(ret, bool)
    return ret
# Buggy code
def expand(node: Container) -> None:
    type_ = get_ref_type(node)
    if type_ is not None:
        _is_optional, type_ = _resolve_optional(type_)
        if is_dict_annotation(type_):
            node._set_value({})
        else:
            node._set_value(type_)


# Traceback (omegaconf.errors.ValidationError)
Traceback (most recent call last):
File "hydra/_internal/config_load
er_impl.py", line 610, in _load_config_impl
merged = OmegaConf.merge(schema.config, ret.config)
File "omegaconf/omegaconf.py", li
ne 316, in merge
target.merge_with(*others[1:])
File "omegaconf/basecontainer.py"
, line 324, in merge_with
self._format_and_raise(key=None, value=None, cause=e)
File "omegaconf/base.py", line 10
1, in _format_and_raise
type_override=type_override,
File "omegaconf/_utils.py", line
675, in format_and_raise
_raise(ex, cause)
File "omegaconf/_utils.py", line
591, in _raise
raise ex  # set end OC_CAUSE=1 for full backtrace
omegaconf.errors.ValidationError: Invalid value assigned : _GenericAlias is not a subclass of ListConfig or list.
full_key:
reference_type=Optional[Dict[Union[str, Enum], Any]]
object_type=dict

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "hydra/_internal/utils.py",
line 203, in run_and_report
return func()
File "hydra/_internal/utils.py",
line 355, in <lambda>
overrides=args.overrides,
File "hydra/_internal/hydra.py",
line 102, in run
run_mode=RunMode.RUN,
File "hydra/_internal/hydra.py",
line 512, in compose_config
from_shell=from_shell,
File "hydra/_internal/config_loader_impl.py", line 153, in load_configuration
from_shell=from_shell,
File "hydra/_internal/config_loader_impl.py", line 256, in _load_configuration
run_mode=run_mode,
File "hydra/_internal/config_loader_impl.py", line 797, in _merge_defaults_into_config
hydra_cfg = merge_defaults_list_into_config(hydra_cfg, user_list)
File "hydra/_internal/config_loader_impl.py", line 775, in merge_defaults_list_into_config
package_override=default1.package,
File "hydra/_internal/config_loader_impl.py", line 690, in _merge_config
package_override=package_override,
File "hydra/_internal/config_loader_impl.py", line 622, in _load_config_impl
) from e
hydra.errors.ConfigCompositionException: Error merging 'lr_scheduler/multi_step' with schema

# Fixed code
def expand(node: Container) -> None:
    type_ = get_ref_type(node)
    if type_ is not None:
        _is_optional, type_ = _resolve_optional(type_)
        if is_dict_annotation(type_):
            node._set_value({})
        elif is_list_annotation(type_):
            node._set_value([])
        else:
            node._set_value(type_)
# Buggy code
def _fetch_reference_injections(
    fn: Callable[..., Any],
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
    signature = inspect.signature(fn)

    injections = {}
    closing = {}
    for parameter_name, parameter in signature.parameters.items():
        if not isinstance(parameter.default, _Marker) and not _is_fastapi_depends(
            parameter.default
        ):
            continue

        marker = parameter.default

        if _is_fastapi_depends(marker):
            marker = marker.dependency

            if not isinstance(marker, _Marker):
                continue

        if isinstance(marker, Closing):
            marker = marker.provider
            closing[parameter_name] = marker

        injections[parameter_name] = marker
    return injections, closing


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/ventaquil/Git/project/package/__main__.py", line 86, in <module>
sys.exit(main())
File "/home/ventaquil/Git/project/package/__main__.py", line 67, in main
container.wire(modules=[http, manager, socketio], packages=[model])
File "src/dependency_injector/containers.pyx", line 222, in dependency_injector.containers.DynamicContainer.wire
File "/home/ventaquil/Git/project/cluster/venv/lib/python3.9/site-packages/dependency_injector/wiring.py", line 230, in wire
_patch_method(member, method_name, method, providers_map)
File "/home/ventaquil/Git/project/venv/lib/python3.9/site-packages/dependency_injector/wiring.py", line 302, in _patch_method
reference_injections, reference_closing = _fetch_reference_injections(fn)
File "/home/ventaquil/Git/project/venv/lib/python3.9/site-packages/dependency_injector/wiring.py", line 336, in _fetch_reference_injections
signature = inspect.signature(fn)
File "/usr/lib/python3.9/inspect.py", line 3118, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
File "/usr/lib/python3.9/inspect.py", line 2867, in from_callable
return _signature_from_callable(obj, sigcls=cls,
File "/usr/lib/python3.9/inspect.py", line 2398, in _signature_from_callable
raise ValueError(
ValueError: no signature found for builtin type <class 'types.GenericAlias'>

# Fixed code
def _fetch_reference_injections(
    fn: Callable[..., Any],
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
    # # Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362
    if GenericAlias and fn is GenericAlias:
        fn = fn.__init__

    signature = inspect.signature(fn)

    injections = {}
    closing = {}
    for parameter_name, parameter in signature.parameters.items():
        if not isinstance(parameter.default, _Marker) and not _is_fastapi_depends(
            parameter.default
        ):
            continue

        marker = parameter.default

        if _is_fastapi_depends(marker):
            marker = marker.dependency

            if not isinstance(marker, _Marker):
                continue

        if isinstance(marker, Closing):
            marker = marker.provider
            closing[parameter_name] = marker

        injections[parameter_name] = marker
    return injections, closing
# Buggy code
def _fetch_modules(package):
    modules = [package]
    for loader, module_name, is_pkg in pkgutil.walk_packages(
        path=package.__path__,
        prefix=package.__name__ + ".",
    ):
        module = loader.find_module(module_name).load_module(module_name)
        modules.append(module)
    return modules


# Traceback (TypeError)
INFO:root:configuration completed
INFO:root:Configuration container wired successfully
INFO:root:Initializing model...
INFO:root:model: <dependency_injector.wiring.Provide object at 0x00000235228E4250>
Traceback (most recent call last):
File "c:/Users/Federico/Desktop/DeepCleverBot/bot/app.py", line 24, in <module>
bot = Bot()
File "C:\Users\Federico\anaconda3\envs\deepcleverbot\lib\site-packages\dependency_injector\wiring.py", line 319, in _patched
to_inject[injection] = provider()
File "src/dependency_injector/providers.pyx", line 160, in dependency_injector.providers.Provider.__call__
File "src/dependency_injector/providers.pyx", line 2130, in dependency_injector.providers.Singleton._provide
File "src/dependency_injector/providers.pxd", line 450, in dependency_injector.providers.__factory_call
File "src/dependency_injector/providers.pxd", line 436, in dependency_injector.providers.__callable_call
File "src/dependency_injector/providers.pxd", line 432, in dependency_injector.providers.__call
File "c:\Users\Federico\Desktop\DeepCleverBot\bot\src\QA\QA.py", line 13, in __init__
self.init_model()
File "c:\Users\Federico\Desktop\DeepCleverBot\bot\src\QA\QA.py", line 18, in init_model
self.tokenizer = BertTokenizer.from_pretrained(self.model, return_token_type_ids = True)
File "C:\Users\Federico\anaconda3\envs\deepcleverbot\lib\site-packages\transformers\tokenization_utils_base.py", line 1516, in from_pretrained
if os.path.isfile(pretrained_model_name_or_path) or is_remote_url(pretrained_model_name_or_path):
File "C:\Users\Federico\anaconda3\envs\deepcleverbot\lib\genericpath.py", line 30, in isfile
st = os.stat(path)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not Provide

# Fixed code
def _fetch_modules(package):
    modules = [package]
    for module_info in pkgutil.walk_packages(
        path=package.__path__,
        prefix=package.__name__ + ".",
    ):
        module = importlib.import_module(module_info.name)
        modules.append(module)
    return modules
# Buggy code
def hashlib_new(context):
    if isinstance(context.call_function_name_qual, str):
        qualname_list = context.call_function_name_qual.split(".")
        func = qualname_list[-1]
        if "hashlib" in qualname_list and func == "new":
            args = context.call_args
            keywords = context.call_keywords
            name = args[0] if args else keywords["name"]
            if name.lower() in ("md4", "md5"):
                return bandit.Issue(
                    severity=bandit.MEDIUM,
                    confidence=bandit.HIGH,
                    text="Use of insecure MD4 or MD5 hash function.",
                    lineno=context.node.lineno,
                )


# Traceback (AttributeError)
$ bandit test_hash_new.py
...
[tester]        ERROR   Bandit internal error running: hashlib_new on file test_hash_new.py at line 4: 'NoneType' object has no attribute 'lower'Traceback (most recent call last):
File "/home/pshchelo/.virtualenvs/bandit/lib/python3.6/site-packages/bandit/core/tester.py", line 64, in run_tests
result = test(context)
File "/home/pshchelo/.virtualenvs/bandit/lib/python3.6/site-packages/bandit/plugins/hashlib_new_insecure_functions.py", line 57, in hashlib_new
if name.lower() in ('md4', 'md5'):
AttributeError: 'NoneType' object has no attribute 'lower'
...

# Fixed code
def hashlib_new(context):
    if isinstance(context.call_function_name_qual, str):
        qualname_list = context.call_function_name_qual.split(".")
        func = qualname_list[-1]
        if "hashlib" in qualname_list and func == "new":
            args = context.call_args
            keywords = context.call_keywords
            name = args[0] if args else keywords["name"]
            if isinstance(name, str) and name.lower() in ("md4", "md5"):
                return bandit.Issue(
                    severity=bandit.MEDIUM,
                    confidence=bandit.HIGH,
                    text="Use of insecure MD4 or MD5 hash function.",
                    lineno=context.node.lineno,
                )
# Buggy code
def transform2call(var):
    if isinstance(var, ast.BinOp):
        is_mod = isinstance(var.op, ast.Mod)
        is_left_str = isinstance(var.left, ast.Str)
        if is_mod and is_left_str:
            new_call = ast.Call()
            new_call.args = []
            new_call.args = []
            new_call.starargs = None
            new_call.keywords = None
            new_call.kwargs = None
            new_call.lineno = var.lineno
            new_call.func = ast.Attribute()
            new_call.func.value = var.left
            new_call.func.attr = "format"
            if isinstance(var.right, ast.Tuple):
                new_call.args = var.right.elts
            elif isinstance(var.right, ast.Dict):
                new_call.kwargs = var.right
            else:
                new_call.args = [var.right]
            return new_call


# Traceback (AttributeError)
Bandit internal error running: django_mark_safe on file /home/travis/build/PyCQA/bandit/examples/mark_safe_secure.py at line 33: 'Call' object has no attribute 'kwargs'Traceback (most recent call last):
File "/home/travis/build/PyCQA/bandit/bandit/core/tester.py", line 64, in run_tests
result = test(context)
File "/home/travis/build/PyCQA/bandit/bandit/plugins/django_xss.py", line 279, in django_mark_safe
return check_risk(context.node)
File "/home/travis/build/PyCQA/bandit/bandit/plugins/django_xss.py", line 232, in check_risk
secure = evaluate_call(xss_var, parent)
File "/home/travis/build/PyCQA/bandit/bandit/plugins/django_xss.py", line 154, in evaluate_call
if call.keywords or call.kwargs:
AttributeError: 'Call' object has no attribute 'kwargs'

# Fixed code
def transform2call(var):
    if isinstance(var, ast.BinOp):
        is_mod = isinstance(var.op, ast.Mod)
        is_left_str = isinstance(var.left, ast.Str)
        if is_mod and is_left_str:
            new_call = ast.Call()
            new_call.args = []
            new_call.args = []
            if six.PY2:
                new_call.starargs = None
            new_call.keywords = None
            if six.PY2:
                new_call.kwargs = None
            new_call.lineno = var.lineno
            new_call.func = ast.Attribute()
            new_call.func.value = var.left
            new_call.func.attr = "format"
            if isinstance(var.right, ast.Tuple):
                new_call.args = var.right.elts
            elif six.PY2 and isinstance(var.right, ast.Dict):
                new_call.kwargs = var.right
            else:
                new_call.args = [var.right]
            return new_call
# Buggy code
def has_shell(context):
    keywords = context.node.keywords
    if "shell" in context.call_keywords:
        for key in keywords:
            if key.arg == "shell":
                val = key.value
                if isinstance(val, ast.Num):
                    return bool(val.n)
                if isinstance(val, ast.List):
                    return bool(val.elts)
                if isinstance(val, ast.Dict):
                    return bool(val.keys)
                if isinstance(val, ast.Name):
                    if val.id in ["False", "None"]:
                        return False
                return True
    return False


# Traceback (AttributeError)
Bandit internal error running: django_mark_safe on file /home/travis/build/PyCQA/bandit/examples/mark_safe_secure.py at line 33: 'Call' object has no attribute 'kwargs'Traceback (most recent call last):
File "/home/travis/build/PyCQA/bandit/bandit/core/tester.py", line 64, in run_tests
result = test(context)
File "/home/travis/build/PyCQA/bandit/bandit/plugins/django_xss.py", line 279, in django_mark_safe
return check_risk(context.node)
File "/home/travis/build/PyCQA/bandit/bandit/plugins/django_xss.py", line 232, in check_risk
secure = evaluate_call(xss_var, parent)
File "/home/travis/build/PyCQA/bandit/bandit/plugins/django_xss.py", line 154, in evaluate_call
if call.keywords or call.kwargs:
AttributeError: 'Call' object has no attribute 'kwargs'

# Fixed code
def has_shell(context):
    keywords = context.node.keywords
    result = False
    if "shell" in context.call_keywords:
        for key in keywords:
            if key.arg == "shell":
                val = key.value
                if isinstance(val, ast.Num):
                    result = bool(val.n)
                elif isinstance(val, ast.List):
                    result = bool(val.elts)
                elif isinstance(val, ast.Dict):
                    result = bool(val.keys)
                elif isinstance(val, ast.Name) and val.id in ["False", "None"]:
                    result = False
                elif not six.PY2 and isinstance(val, ast.NameConstant):
                    result = val.value
                else:
                    result = True
    return result
# Buggy code
def log_parameters_lite(log_file, args):
    log_params = {}
    for param_name, param_value in args.__dict__.items():
        log_params[param_name] = param_value
    if args.args_data is not None:
        stub_method = pickle.loads(base64.b64decode(args.args_data))
        method_args = stub_method.kwargs
        log_params["json_args"] = dict()
        for k, v in list(method_args.items()):
            log_params["json_args"][k] = stub_to_json(v)
        kwargs = stub_method.obj.kwargs
        for k in ["baseline", "env", "policy"]:
            if k in kwargs:
                log_params["json_args"][k] = stub_to_json(kwargs.pop(k))
        log_params["json_args"]["algo"] = stub_to_json(stub_method.obj)
    mkdir_p(os.path.dirname(log_file))
    with open(log_file, "w") as f:
        json.dump(log_params, f, indent=2, sort_keys=True, cls=MyEncoder)


# Traceback (TypeError)
Traceback (most recent call last):
File "/Users/jonathon/Documents/garage/garage/scripts/run_experiment.py", line 191, in <module>
run_experiment(sys.argv)
File "/Users/jonathon/Documents/garage/garage/scripts/run_experiment.py", line 146, in run_experiment
logger.log_parameters_lite(params_log_file, args)
File "/Users/jonathon/Documents/garage/garage/garage/misc/logger.py", line 372, in log_parameters_lite
json.dump(log_params, f, indent=2, sort_keys=True, cls=MyEncoder)
File "/anaconda2/envs/garage/lib/python3.6/json/__init__.py", line 179, in dump
for chunk in iterable:
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 430, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
[Previous line repeated 1 more times]
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 437, in _iterencode
o = _default(o)
File "/Users/jonathon/Documents/garage/garage/garage/misc/logger.py", line 352, in default
return json.JSONEncoder.default(self, o)
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'TimeLimit' is not JSON serializable

# Fixed code
def log_parameters_lite(log_file, args):
    log_params = {}
    for param_name, param_value in args.__dict__.items():
        log_params[param_name] = param_value
    if args.args_data is not None:
        log_params["json_args"] = dict()
    mkdir_p(os.path.dirname(log_file))
    with open(log_file, "w") as f:
        json.dump(log_params, f, indent=2, sort_keys=True, cls=MyEncoder)
# Buggy code
def log_variant(log_file, variant_data):
    mkdir_p(os.path.dirname(log_file))
    if hasattr(variant_data, "dump"):
        variant_data = variant_data.dump()
    variant_json = stub_to_json(variant_data)
    with open(log_file, "w") as f:
        json.dump(variant_json, f, indent=2, sort_keys=True, cls=MyEncoder)


# Traceback (TypeError)
Traceback (most recent call last):
File "/Users/jonathon/Documents/garage/garage/scripts/run_experiment.py", line 191, in <module>
run_experiment(sys.argv)
File "/Users/jonathon/Documents/garage/garage/scripts/run_experiment.py", line 146, in run_experiment
logger.log_parameters_lite(params_log_file, args)
File "/Users/jonathon/Documents/garage/garage/garage/misc/logger.py", line 372, in log_parameters_lite
json.dump(log_params, f, indent=2, sort_keys=True, cls=MyEncoder)
File "/anaconda2/envs/garage/lib/python3.6/json/__init__.py", line 179, in dump
for chunk in iterable:
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 430, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
[Previous line repeated 1 more times]
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 437, in _iterencode
o = _default(o)
File "/Users/jonathon/Documents/garage/garage/garage/misc/logger.py", line 352, in default
return json.JSONEncoder.default(self, o)
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'TimeLimit' is not JSON serializable

# Fixed code
def log_variant(log_file, variant_data):
    mkdir_p(os.path.dirname(log_file))
    if hasattr(variant_data, "dump"):
        variant_data = variant_data.dump()
    with open(log_file, "w") as f:
        json.dump(variant_data, f, indent=2, sort_keys=True, cls=MyEncoder)
# Buggy code
def load_progress(progress_csv_path):
    print("Reading %s" % progress_csv_path)
    entries = dict()
    with open(progress_csv_path, "r") as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            for k, v in row.items():
                if k not in entries:
                    entries[k] = []
                try:
                    entries[k].append(float(v))
                except:
                    entries[k].append(0.0)
    entries = dict([(k, np.array(v)) for k, v in entries.items()])
    return entries


# Traceback (TypeError)
Traceback (most recent call last):
File "/Users/jonathon/Documents/garage/garage/scripts/run_experiment.py", line 191, in <module>
run_experiment(sys.argv)
File "/Users/jonathon/Documents/garage/garage/scripts/run_experiment.py", line 146, in run_experiment
logger.log_parameters_lite(params_log_file, args)
File "/Users/jonathon/Documents/garage/garage/garage/misc/logger.py", line 372, in log_parameters_lite
json.dump(log_params, f, indent=2, sort_keys=True, cls=MyEncoder)
File "/anaconda2/envs/garage/lib/python3.6/json/__init__.py", line 179, in dump
for chunk in iterable:
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 430, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
[Previous line repeated 1 more times]
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 437, in _iterencode
o = _default(o)
File "/Users/jonathon/Documents/garage/garage/garage/misc/logger.py", line 352, in default
return json.JSONEncoder.default(self, o)
File "/anaconda2/envs/garage/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'TimeLimit' is not JSON serializable

# Fixed code
def load_progress(progress_csv_path):
    print("Reading %s" % progress_csv_path)
    entries = dict()
    with open(progress_csv_path, "r") as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            for k, v in row.items():
                if k not in entries:
                    entries[k] = []
                try:
                    entries[k].append(float(v))
                except:  # noqa
                    entries[k].append(0.0)
    entries = dict([(k, np.array(v)) for k, v in entries.items()])
    return entries
# Buggy code
def __init__(self, old_version: str, current_version: str) -> None:
    super().__init__(
        "Build directory has been generated with Meson version {}, "
        "which is incompatible with current version {}.".format(
            old_version, current_version
        )
    )
    self.old_version = old_version
    self.current_version = current_version


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/mesonbuild/mesonmain.py", line 131, in run
return options.run_func(options)
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 1220, in run
return th.doit()
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 975, in doit
self.run_tests(tests)
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 1130, in run_tests
self.drain_futures(futures)
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 1146, in drain_futures
self.process_test_result(result.result())
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 432, in result
return self.__get_result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 628, in run
cmd = self._get_cmd()
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 612, in _get_cmd
elif self.test.cmd_is_built and self.test.needs_exe_wrapper:
AttributeError: 'TestSerialisation' object has no attribute 'cmd_is_built'

# Fixed code
def __init__(self, old_version: str, current_version: str) -> None:
    super().__init__(
        "Build directory has been generated with Meson version {}, "
        "which is incompatible with the current version {}.".format(
            old_version, current_version
        )
    )
    self.old_version = old_version
    self.current_version = current_version
# Buggy code
def major_versions_differ(v1, v2):
    return v1.split(".")[0:2] != v2.split(".")[0:2]


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/mesonbuild/mesonmain.py", line 131, in run
return options.run_func(options)
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 1220, in run
return th.doit()
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 975, in doit
self.run_tests(tests)
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 1130, in run_tests
self.drain_futures(futures)
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 1146, in drain_futures
self.process_test_result(result.result())
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 432, in result
return self.__get_result()
File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
raise self._exception
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 628, in run
cmd = self._get_cmd()
File "/usr/lib/python3.8/site-packages/mesonbuild/mtest.py", line 612, in _get_cmd
elif self.test.cmd_is_built and self.test.needs_exe_wrapper:
AttributeError: 'TestSerialisation' object has no attribute 'cmd_is_built'

# Fixed code
def major_versions_differ(v1: str, v2: str) -> bool:
    return v1.split(".")[0:2] != v2.split(".")[0:2]
# Buggy code
def _func_custom_target_impl(self, node, args, kwargs):
    "Implementation-only, without FeatureNew checks, for internal use"
    name = args[0]
    kwargs["install_mode"] = self._get_kwarg_install_mode(kwargs)
    tg = CustomTargetHolder(
        build.CustomTarget(name, self.subdir, self.subproject, kwargs), self
    )
    self.add_target(name, tg.held_object)
    return tg


# Traceback (AttributeError)
$ meson -v
0.44.0

$ meson introspect --target-files egd_tables.h@cus
Traceback (most recent call last):
File "/usr/bin/meson", line 37, in <module>
sys.exit(main())
File "/usr/bin/meson", line 34, in main
return mesonmain.run(sys.argv[1:], launcher)
File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 297, in run
return mintro.run(remaining_args)
File "/usr/lib/python3.6/site-packages/mesonbuild/mintro.py", line 236, in run
list_target_files(options.target_files, coredata, builddata)
File "/usr/lib/python3.6/site-packages/mesonbuild/mintro.py", line 118, in list_target_files
sources = [os.path.join(i.subdir, i.fname) for i in sources]
File "/usr/lib/python3.6/site-packages/mesonbuild/mintro.py", line 118, in <listcomp>
sources = [os.path.join(i.subdir, i.fname) for i in sources]
AttributeError: 'str' object has no attribute 'subdir'

# Fixed code
def _func_custom_target_impl(self, node, args, kwargs):
    "Implementation-only, without FeatureNew checks, for internal use"
    name = args[0]
    kwargs["install_mode"] = self._get_kwarg_install_mode(kwargs)
    if "input" in kwargs:
        try:
            kwargs["input"] = self.source_strings_to_files(
                extract_as_list(kwargs, "input")
            )
        except mesonlib.MesonException:
            mlog.warning(
                """Custom target input \'%s\' can\'t be converted to File object(s).
This will become a hard error in the future."""
                % kwargs["input"]
            )
    tg = CustomTargetHolder(
        build.CustomTarget(name, self.subdir, self.subproject, kwargs), self
    )
    self.add_target(name, tg.held_object)
    return tg
# Buggy code
def source_strings_to_files(self, sources):
    results = []
    mesonlib.check_direntry_issues(sources)
    if not isinstance(sources, list):
        sources = [sources]
    for s in sources:
        if isinstance(
            s,
            (
                mesonlib.File,
                GeneratedListHolder,
                CustomTargetHolder,
                CustomTargetIndexHolder,
            ),
        ):
            pass
        elif isinstance(s, str):
            self.validate_within_subproject(self.subdir, s)
            s = mesonlib.File.from_source_file(
                self.environment.source_dir, self.subdir, s
            )
        else:
            raise InterpreterException(
                "Source item is {!r} instead of string or File-type object".format(s)
            )
        results.append(s)
    return results


# Traceback (AttributeError)
$ meson -v
0.44.0

$ meson introspect --target-files egd_tables.h@cus
Traceback (most recent call last):
File "/usr/bin/meson", line 37, in <module>
sys.exit(main())
File "/usr/bin/meson", line 34, in main
return mesonmain.run(sys.argv[1:], launcher)
File "/usr/lib/python3.6/site-packages/mesonbuild/mesonmain.py", line 297, in run
return mintro.run(remaining_args)
File "/usr/lib/python3.6/site-packages/mesonbuild/mintro.py", line 236, in run
list_target_files(options.target_files, coredata, builddata)
File "/usr/lib/python3.6/site-packages/mesonbuild/mintro.py", line 118, in list_target_files
sources = [os.path.join(i.subdir, i.fname) for i in sources]
File "/usr/lib/python3.6/site-packages/mesonbuild/mintro.py", line 118, in <listcomp>
sources = [os.path.join(i.subdir, i.fname) for i in sources]
AttributeError: 'str' object has no attribute 'subdir'

# Fixed code
def source_strings_to_files(self, sources):
    results = []
    mesonlib.check_direntry_issues(sources)
    if not isinstance(sources, list):
        sources = [sources]
    for s in sources:
        if isinstance(
            s,
            (mesonlib.File, GeneratedListHolder, TargetHolder, CustomTargetIndexHolder),
        ):
            pass
        elif isinstance(s, str):
            self.validate_within_subproject(self.subdir, s)
            s = mesonlib.File.from_source_file(
                self.environment.source_dir, self.subdir, s
            )
        else:
            raise InterpreterException(
                "Source item is {!r} instead of string or File-type object".format(s)
            )
        results.append(s)
    return results
# Buggy code
def __init__(self, build):
    self.build = build
    self.environment = build.environment
    self.processed_targets = {}
    self.build_to_src = os.path.relpath(
        self.environment.get_source_dir(), self.environment.get_build_dir()
    )


# Traceback (ValueError)
Stdout:
Traceback (most recent call last):
File "D:\dev\meson\mesonbuild\mesonmain.py", line 368, in run
app.generate()
File "D:\dev\meson\mesonbuild\mesonmain.py", line 150, in generate
self._generate(env)
File "D:\dev\meson\mesonbuild\mesonmain.py", line 168, in _generate
g = ninjabackend.NinjaBackend(b)
File "D:\dev\meson\mesonbuild\backend\ninjabackend.py", line 143, in __init__
super().__init__(build)
File "D:\dev\meson\mesonbuild\backend\backends.py", line 111, in __init__
self.environment.get_build_dir())
File "C:\Python36\lib\ntpath.py", line 585, in relpath
path_drive, start_drive))
ValueError: path is on mount 'D:', start on mount 'C:'

# Fixed code
def __init__(self, build):
    self.build = build
    self.environment = build.environment
    self.processed_targets = {}
    self.build_to_src = mesonlib.relpath(
        self.environment.get_source_dir(), self.environment.get_build_dir()
    )
# Buggy code
def __init__(
    self,
    fname,
    outdir,
    aliases,
    strip,
    install_name_mappings,
    install_rpath,
    install_mode,
):
    self.fname = fname
    self.outdir = outdir
    self.aliases = aliases
    self.strip = strip
    self.install_name_mappings = install_name_mappings
    self.install_rpath = install_rpath
    self.install_mode = install_mode


# Traceback (FileNotFoundError)
Traceback (most recent call last):
File "d:\\projects\\cerbero\\meson\\master\\build\\build-tools\\Scripts\\meson.py", line 4, in <module>
__import__('pkg_resources').run_script('meson==0.47.0', 'meson.py')
File "c:\Python36-32\lib\site-packages\pkg_resources\__init__.py", line 658, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "c:\Python36-32\lib\site-packages\pkg_resources\__init__.py", line 1438, in run_script
exec(code, namespace, namespace)
File "d:\projects\cerbero\meson\master\build\build-tools\lib\site-packages\meson-0.47.0-py3.6.egg\EGG-INFO\scripts\meson.py", line 29, in <module>
sys.exit(mesonmain.main())
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\mesonmain.py", line 367, in main
return run(sys.argv[1:], launcher)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\mesonmain.py", line 281, in run
return minstall.run(remaining_args)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 466, in run
installer.do_install(datafilename)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 298, in do_install
self.install_targets(d)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 387, in install_targets
fname = check_for_stampfile(t.fname)
File "d:\projects\cerbero\meson\master\build\build-tools\Lib\site-packages\meson-0.47.0-py3.6.egg\mesonbuild\minstall.py", line 170, in check_for_stampfile
if os.stat(fname).st_size == 0:
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'tls/gnutls\\giognutls.lib'
FAILED: meson-install
"c:\\Python36-32\\python.exe" "d:\\projects\\cerbero\\meson\\master\\build\\build-tools\\Scripts\\meson.py" "install" "--no-rebuild"
ninja: build stopped: subcommand failed.

# Fixed code
def __init__(
    self,
    fname,
    outdir,
    aliases,
    strip,
    install_name_mappings,
    install_rpath,
    install_mode,
    optional=False,
):
    self.fname = fname
    self.outdir = outdir
    self.aliases = aliases
    self.strip = strip
    self.install_name_mappings = install_name_mappings
    self.install_rpath = install_rpath
    self.install_mode = install_mode
    self.optional = optional
# Buggy code
def generate_msvc_pch_command(self, target, compiler, pch):
    if len(pch) != 2:
        raise RuntimeError(
            "MSVC requires one header and one source to produce precompiled headers."
        )
    header = pch[0]
    source = pch[1]
    pchname = compiler.get_pch_name(header)
    dst = os.path.join(self.get_target_private_dir(target), pchname)

    commands = []
    commands += self.generate_basic_compiler_args(target, compiler)
    just_name = os.path.split(header)[1]
    (objname, pch_args) = compiler.gen_pch_args(just_name, source, dst)
    commands += pch_args
    commands += self.get_compile_debugfile_args(compiler, target, objname)
    dep = dst + "." + compiler.get_depfile_suffix()
    return commands, dep, dst, [objname]


# Traceback (IndexError)
Traceback (most recent call last):
File "mesonbuild\mesonmain.py", line 352, in run
File "mesonbuild\mesonmain.py", line 147, in generate
File "mesonbuild\mesonmain.py", line 197, in _generate
File "mesonbuild\backend\vs2010backend.py", line 161, in generate
File "mesonbuild\backend\vs2010backend.py", line 311, in generate_projects
File "mesonbuild\backend\vs2010backend.py", line 864, in gen_vcxproj
IndexError: list index out of range

# Fixed code
def generate_msvc_pch_command(self, target, compiler, pch):
    if len(pch) != 2:
        raise MesonException(
            "MSVC requires one header and one source to produce precompiled headers."
        )
    header = pch[0]
    source = pch[1]
    pchname = compiler.get_pch_name(header)
    dst = os.path.join(self.get_target_private_dir(target), pchname)

    commands = []
    commands += self.generate_basic_compiler_args(target, compiler)
    just_name = os.path.split(header)[1]
    (objname, pch_args) = compiler.gen_pch_args(just_name, source, dst)
    commands += pch_args
    commands += self.get_compile_debugfile_args(compiler, target, objname)
    dep = dst + "." + compiler.get_depfile_suffix()
    return commands, dep, dst, [objname]
# Buggy code
def _find_source_script(self, name, args):
    # Prefer scripts in the current source directory
    search_dir = os.path.join(
        self.interpreter.environment.source_dir, self.interpreter.subdir
    )
    key = (name, search_dir)
    if key in self._found_source_scripts:
        found = self._found_source_scripts[key]
    else:
        found = dependencies.ExternalProgram(name, search_dir=search_dir)
        if found:
            self._found_source_scripts[key] = found
        else:
            raise InterpreterException("Script {!r} not found".format(name))
    return build.RunScript(found.get_command(), args)


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/bin/meson", line 37, in <module>
sys.exit(main())
File "/usr/bin/meson", line 34, in main
return mesonmain.run(launcher, sys.argv[1:])
File "/home/zbyszek/.local/lib/python3.5/site-packages/meson-0.40.0.dev1-py3.5.egg/mesonbuild/mesonmain.py", line 260, in run
sys.exit(run_script_command(args[1:]))
File "/home/zbyszek/.local/lib/python3.5/site-packages/meson-0.40.0.dev1-py3.5.egg/mesonbuild/mesonmain.py", line 248, in run_script_command
return cmdfunc(cmdargs)
File "/home/zbyszek/.local/lib/python3.5/site-packages/meson-0.40.0.dev1-py3.5.egg/mesonbuild/scripts/meson_install.py", line 306, in run
do_install(datafilename)
File "/home/zbyszek/.local/lib/python3.5/site-packages/meson-0.40.0.dev1-py3.5.egg/mesonbuild/scripts/meson_install.py", line 129, in do_install
run_install_script(d)
File "/home/zbyszek/.local/lib/python3.5/site-packages/meson-0.40.0.dev1-py3.5.egg/mesonbuild/scripts/meson_install.py", line 193, in run_install_script
name = ' '.join(script + args)
TypeError: sequence item 0: expected str instance, NoneType found

# Fixed code
def _find_source_script(self, name, args):
    # Prefer scripts in the current source directory
    search_dir = os.path.join(
        self.interpreter.environment.source_dir, self.interpreter.subdir
    )
    key = (name, search_dir)
    if key in self._found_source_scripts:
        found = self._found_source_scripts[key]
    else:
        found = dependencies.ExternalProgram(name, search_dir=search_dir)
        if found.found():
            self._found_source_scripts[key] = found
        else:
            raise InterpreterException("Script {!r} not found".format(name))
    return build.RunScript(found.get_command(), args)
# Buggy code
def gen_custom_target_vcxproj(self, target, ofname, guid):
    root = self.create_basic_crap(target)
    action = ET.SubElement(root, "ItemDefinitionGroup")
    customstep = ET.SubElement(action, "CustomBuildStep")
    # We need to always use absolute paths because our invocation is always
    # from the target dir, not the build root.
    target.absolute_paths = True
    (srcs, ofilenames, cmd) = self.eval_custom_target_command(target, True)
    cmd_templ = """"%s" """ * len(cmd)
    ET.SubElement(customstep, "Command").text = cmd_templ % tuple(cmd)
    ET.SubElement(customstep, "Outputs").text = ";".join(ofilenames)
    ET.SubElement(customstep, "Inputs").text = ";".join(srcs)
    ET.SubElement(root, "Import", Project="$(VCTargetsPath)\Microsoft.Cpp.targets")
    tree = ET.ElementTree(root)
    tree.write(ofname, encoding="utf-8", xml_declaration=True)


# Traceback (AttributeError)
Traceback (most recent call last):
File "C:\projects\meson\mesonbuild\mesonmain.py", line 279, in run
app.generate()
File "C:\projects\meson\mesonbuild\mesonmain.py", line 169, in generate
g.generate(intr)
File "C:\projects\meson\mesonbuild\backend\vs2010backend.py", line 168, in generate
self.generate_solution(sln_filename, projlist)
File "C:\projects\meson\mesonbuild\backend\vs2010backend.py", line 233, in generate_solution
all_deps = self.determine_deps(p)
File "C:\projects\meson\mesonbuild\backend\vs2010backend.py", line 203, in determine_deps
all_deps[d.get_id()] = True
AttributeError: 'GeneratedList' object has no attribute 'get_id'

# Fixed code
def gen_custom_target_vcxproj(self, target, ofname, guid):
    root = self.create_basic_crap(target)
    action = ET.SubElement(root, "ItemDefinitionGroup")
    customstep = ET.SubElement(action, "CustomBuildStep")
    # We need to always use absolute paths because our invocation is always
    # from the target dir, not the build root.
    target.absolute_paths = True
    (srcs, ofilenames, cmd) = self.eval_custom_target_command(target, True)
    ET.SubElement(customstep, "Command").text = " ".join(self.quote_arguments(cmd))
    ET.SubElement(customstep, "Outputs").text = ";".join(ofilenames)
    ET.SubElement(customstep, "Inputs").text = ";".join(srcs)
    ET.SubElement(root, "Import", Project="$(VCTargetsPath)\Microsoft.Cpp.targets")
    self.generate_custom_generator_commands(target, root)
    tree = ET.ElementTree(root)
    tree.write(ofname, encoding="utf-8", xml_declaration=True)