gurudesh/pytracebugs huggingface dataset:
# Buggy code
def df_to_data(zone_key, day, df, logger):
    df = df.dropna(axis=1, how="any")
    # Check for empty dataframe
    if df.shape == (1, 1):
        return []
    df = df.drop(["Intercambio Sur", "Intercambio Norte", "Total"], errors="ignore")
    df = df.iloc[:, :-1]

    results = []
    unknown_plants = set()
    hour = 0
    for column in df:
        data = empty_record(zone_key)
        data_time = day.replace(hour=hour, minute=0, second=0, microsecond=0).datetime
        for index, value in df[column].items():
            source = POWER_PLANTS.get(index)
            if not source:
                source = "unknown"
                unknown_plants.add(index)
            data["datetime"] = data_time
            data["production"][source] += max(0.0, value)
        hour += 1
        results.append(data)

    for plant in unknown_plants:
        logger.warning(
            "{} is not mapped to generation type".format(plant), extra={"key": zone_key}
        )

    return results


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/feeder/lib/fetch_data.py", line 131, in launch_parsers
**parser_kwargs)
File "/home/contrib/parsers/CR.py", line 178, in fetch_production
jsf_view_state = soup.select('#javax.faces.ViewState')[0]['value']
IndexError: list index out of range

# Fixed code
def df_to_data(zone_key, day, df, logger):
    df = df.dropna(axis=1, how="any")
    # Check for empty dataframe
    if df.shape == (1, 1):
        return []
    df = df.drop(["Intercambio Sur", "Intercambio Norte", "Total"], errors="ignore")
    df = df.iloc[:, :-1]

    results = []
    unknown_plants = set()
    hour = 0
    for column in df:
        data = empty_record(zone_key)
        data_time = day.replace(hour=hour, minute=0, second=0, microsecond=0).datetime
        for index, value in df[column].items():
            source = POWER_PLANTS.get(index)
            if not source:
                source = "unknown"
                unknown_plants.add(index)
            data["datetime"] = data_time
            data["production"][source] += max(0.0, value)
        hour += 1
        results.append(data)

    for plant in unknown_plants:
        logger.warning(
            "{} is not mapped to generation type".format(plant), extra={"key": zone_key}
        )

    return results
# Buggy code
def extract_hidden_values(req):
    """
    Gets current aspx page values to enable post requests to be sent.
    Returns a dictionary.
    """

    soup = BeautifulSoup(req.content, "html.parser")

    # Find and define parameters needed to send a POST request.
    viewstategenerator = soup.find("input", attrs={"id": "__VIEWSTATEGENERATOR"})[
        "value"
    ]
    viewstate = soup.find("input", attrs={"id": "__VIEWSTATE"})["value"]
    eventvalidation = soup.find("input", attrs={"id": "__EVENTVALIDATION"})["value"]
    jschartviewerstate = soup.find(
        "input", attrs={"id": "MainContent_ctl17_JsChartViewerState"}
    )["value"]

    hidden_values = {
        "viewstategenerator": viewstategenerator,
        "viewstate": viewstate,
        "eventvalidation": eventvalidation,
        "jschartviewerstate": jschartviewerstate,
    }

    return hidden_values


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/feeder/lib/fetch_data.py", line 130, in launch_parsers
**parser_kwargs)
File "/home/electricitymap/parsers/MY_WM.py", line 309, in fetch_exchange
hvdc_hidden_values = extract_hidden_values(hvdc_switch_req)
File "/home/electricitymap/parsers/MY_WM.py", line 176, in extract_hidden_values
viewstategenerator = soup.find("input", attrs={'id': '__VIEWSTATEGENERATOR'})['value']
TypeError: 'NoneType' object is not subscriptable

# Fixed code
def extract_hidden_values(req):
    """
    Gets current aspx page values to enable post requests to be sent.
    Returns a dictionary.
    """

    soup = BeautifulSoup(req.content, "html.parser")

    # Find and define parameters needed to send a POST request.
    try:
        viewstategenerator = soup.find("input", attrs={"id": "__VIEWSTATEGENERATOR"})[
            "value"
        ]
        viewstate = soup.find("input", attrs={"id": "__VIEWSTATE"})["value"]
        eventvalidation = soup.find("input", attrs={"id": "__EVENTVALIDATION"})["value"]
        jschartviewerstate = soup.find(
            "input", attrs={"id": "MainContent_ctl17_JsChartViewerState"}
        )["value"]
    except TypeError:
        raise ValueError("No exchange data is currently available for West Malaysia.")

    hidden_values = {
        "viewstategenerator": viewstategenerator,
        "viewstate": viewstate,
        "eventvalidation": eventvalidation,
        "jschartviewerstate": jschartviewerstate,
    }

    return hidden_values
# Buggy code
def data_processer(raw_data, logger):
    """
    Groups dictionaries by datetime key.
    Removes unneeded keys and logs any new ones.
    Returns a list of tuples containing (datetime object, dictionary).
    """

    dt_key = lambda x: x["datetime"]
    grouped = groupby(raw_data, dt_key)

    keys_to_ignore = {"Load", "Net Purchases", "Inadvertent", "PURPA Other"}
    known_keys = GENERATION_MAPPING.keys() | keys_to_ignore

    unmapped = set()
    parsed_data = []
    for group in grouped:
        dt = timestamp_converter(group[0])
        generation = group[1]

        production = {}
        for gen_type in generation:
            production[gen_type["name"]] = float(gen_type["data"])

        current_keys = production.keys() | set()
        unknown_keys = current_keys - known_keys
        unmapped = unmapped | unknown_keys

        keys_to_remove = keys_to_ignore | unknown_keys

        for key in keys_to_remove:
            production.pop(key)

        production = {GENERATION_MAPPING[k]: v for k, v in production.items()}

        parsed_data.append((dt, production))

    for key in unmapped:
        logger.warning(
            "Key '{}' in US-IPC is not mapped to type.".format(key),
            extra={"key": "US-IPC"},
        )

    return parsed_data


# Traceback (KeyError)
Traceback (most recent call last):
File "/home/feeder/lib/fetch_data.py", line 130, in launch_parsers
**parser_kwargs)
File "/home/electricitymap/parsers/US_IPC.py", line 129, in fetch_production
processed_data = data_processer(raw_data, logger)
File "/home/electricitymap/parsers/US_IPC.py", line 83, in data_processer
production.pop(key)
KeyError: 'Net Purchases'

# Fixed code
def data_processer(raw_data, logger):
    """
    Groups dictionaries by datetime key.
    Removes unneeded keys and logs any new ones.
    Returns a list of tuples containing (datetime object, dictionary).
    """

    dt_key = lambda x: x["datetime"]
    grouped = groupby(raw_data, dt_key)

    keys_to_ignore = {"Load", "Net Purchases", "Inadvertent", "PURPA Other"}
    known_keys = GENERATION_MAPPING.keys() | keys_to_ignore

    unmapped = set()
    parsed_data = []
    for group in grouped:
        dt = timestamp_converter(group[0])
        generation = group[1]

        production = {}
        for gen_type in generation:
            production[gen_type["name"]] = float(gen_type["data"])

        current_keys = production.keys() | set()
        unknown_keys = current_keys - known_keys
        unmapped = unmapped | unknown_keys

        keys_to_remove = keys_to_ignore | unknown_keys

        for key in keys_to_remove:
            production.pop(key, None)

        production = {GENERATION_MAPPING[k]: v for k, v in production.items()}

        parsed_data.append((dt, production))

    for key in unmapped:
        logger.warning(
            "Key '{}' in US-IPC is not mapped to type.".format(key),
            extra={"key": "US-IPC"},
        )

    return parsed_data
# Buggy code
def get_data(session=None):
    """Returns generation data as a list of floats."""

    s = session or requests.Session()

    data_response = s.get(data_url)
    raw_data = data_response.text

    data = [float(i) for i in raw_data.split(",")]

    return data


# Traceback (ValueError)
Traceback (most recent call last):
File "feeder_electricity.py", line 176, in fetch_exchange
objs = parser(country_code1, country_code2, session, logger=public_logger)
File "/home/electricitymap/parsers/MD.py", line 113, in fetch_exchange
exchange_status = get_data(session=session)
File "/home/electricitymap/parsers/MD.py", line 31, in get_data
data = [float(i) for i in raw_data.split(',')]
File "/home/electricitymap/parsers/MD.py", line 31, in <listcomp>
data = [float(i) for i in raw_data.split(',')]
ValueError: could not convert string to float:

# Fixed code
def get_data(session=None):
    """Returns generation data as a list of floats."""

    s = session or requests.Session()

    # In order for the data url to return data, cookies from the display url must be obtained then reused.
    response = s.get(display_url)
    data_response = s.get(data_url)
    raw_data = data_response.text
    data = [float(i) for i in raw_data.split(",")]

    return data
# Buggy code
def fetch_SA_battery(session=None):
    """
    Makes a request to the nemlog api for South Australia battery data.
    Returns a float or None.
    """

    today = arrow.now("Australia/Adelaide")
    current = today.format("YYYYMMDD")
    old = today.shift(days=-2).format("YYYYMMDD")
    nemlog_url = "http://nemlog.com.au/api/unit/HPRL1/{}/{}/json".format(old, current)

    s = session or requests.Session()
    req = s.get(nemlog_url)

    data = []
    for line in req.iter_lines():
        data.append(line)

    try:
        latest = json.loads(data[-1])
    except IndexError:
        # No data available.
        return None

    state = float(latest["SCADAVALUE"])

    # Source classifies charge/discharge opposite to EM.
    battery_status = -1 * state

    return battery_status


# Traceback (TypeError)
fetch_production("AUS-SA") ->
Traceback (most recent call last):
File "AU.py", line 558, in <module>
print(fetch_production('AUS-SA'))
File "AU.py", line 422, in fetch_production
data['storage']['battery'] = AU_battery.fetch_SA_battery()
File "/home/chris/electricitymap/parsers/lib/AU_battery.py", line 30, in fetch_SA_battery
latest = json.loads(data[-1])
File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

# Fixed code
def fetch_SA_battery(session=None):
    """
    Makes a request to the nemlog api for South Australia battery data.
    Returns a float or None.
    """

    today = arrow.now("Australia/Adelaide")
    current = today.format("YYYYMMDD")
    old = today.shift(days=-2).format("YYYYMMDD")
    nemlog_url = "http://nemlog.com.au/api/unit/HPRL1/{}/{}/json".format(old, current)

    s = session or requests.Session()
    req = s.get(nemlog_url)
    data = []
    for line in req.iter_lines(decode_unicode=True):
        data.append(line)
    try:
        latest = json.loads(data[-1])
    except IndexError:
        # No data available.
        return None

    state = float(latest["SCADAVALUE"])

    # Source classifies charge/discharge opposite to EM.
    battery_status = -1 * state

    return battery_status
# Buggy code
def fetch_PL():
    parameters = ["B01", "B02", "B03", "B04", "B05", "B06", "B10", "B11", "B12", "B19"]
    output_array = map(fetchValue, parameters)

    data = {
        "countryCode": COUNTRY_CODE,
        "production": {
            "wind": output_array[9],
            "solar": 0,
            "hydro": output_array[6] + output_array[7] + output_array[8],
            "biomass": output_array[0],
            "nuclear": 0,
            "gas": output_array[2] + output_array[3],
            "coal": output_array[1] + output_array[4],
            "oil": output_array[5],
            "unknown": 0,
        },
    }

    return data


# Traceback (IndexError)
Traceback (most recent call last):
File "feeder.py", line 51, in fetch_countries
obj = parser()
File "/home/parsers/PL.py", line 29, in fetch_PL
output_array = map(fetchValue, parameters)
File "/home/parsers/PL.py", line 21, in fetchValue
last = soup.find_all('point')[-1].find_all('quantity')[-1]
IndexError: list index out of range

# Fixed code
def fetch_PL(session=None):
    return fetch_ENTSOE(ENTSOE_DOMAIN, COUNTRY_CODE, session)
# Buggy code
def is_default_argument(node: astroid.node_classes.NodeNG) -> bool:
    """return true if the given Name node is used in function or lambda
    default argument's value
    """
    parent = node.scope()
    if isinstance(parent, (astroid.FunctionDef, astroid.Lambda)):
        for default_node in parent.args.defaults:
            for default_name_node in default_node.nodes_of_class(astroid.Name):
                if default_name_node is node:
                    return True
    return False


# Traceback (NameError)
Traceback (most recent call last):
File "tmp.py", line 11, in <module>
class Wrong:
File "tmp.py", line 14, in Wrong
def work(self) -> self.Result2:
NameError: name 'self' is not defined

# Fixed code
def is_default_argument(
    node: astroid.node_classes.NodeNG,
    scope: Optional[astroid.node_classes.NodeNG] = None,
) -> bool:
    """return true if the given Name node is used in function or lambda
    default argument's value
    """
    if not scope:
        scope = node.scope()
    if isinstance(scope, (astroid.FunctionDef, astroid.Lambda)):
        for default_node in scope.args.defaults:
            for default_name_node in default_node.nodes_of_class(astroid.Name):
                if default_name_node is node:
                    return True
    return False
# Buggy code
def __init__(self, node, scope_type):
    self._atomic = ScopeConsumer(copy.copy(node.locals), {}, scope_type)


# Traceback (NameError)
Traceback (most recent call last):
File "tmp.py", line 11, in <module>
class Wrong:
File "tmp.py", line 14, in Wrong
def work(self) -> self.Result2:
NameError: name 'self' is not defined

# Fixed code
def __init__(self, node, scope_type):
    self._atomic = ScopeConsumer(copy.copy(node.locals), {}, scope_type)
    self.node = node
# Buggy code
def _ignore_class_scope(self, node):
    """
    Return True if the node is in a local class scope, as an assignment.

    :param node: Node considered
    :type node: astroid.Node
    :return: True if the node is in a local class scope, as an assignment. False otherwise.
    :rtype: bool
    """
    # Detect if we are in a local class scope, as an assignment.
    # For example, the following is fair game.
    #
    # class A:
    #    b = 1
    #    c = lambda b=b: b * b
    #
    # class B:
    #    tp = 1
    #    def func(self, arg: tp):
    #        ...
    # class C:
    #    tp = 2
    #    def func(self, arg=tp):
    #        ...

    name = node.name
    frame = node.statement().scope()
    in_annotation_or_default_or_decorator = self._defined_in_function_definition(
        node, frame
    )
    if in_annotation_or_default_or_decorator:
        frame_locals = frame.parent.scope().locals
    else:
        frame_locals = frame.locals
    return not (
        (isinstance(frame, astroid.ClassDef) or in_annotation_or_default_or_decorator)
        and not self._in_lambda_or_comprehension_body(node, frame)
        and name in frame_locals
    )


# Traceback (NameError)
Traceback (most recent call last):
File "tmp.py", line 11, in <module>
class Wrong:
File "tmp.py", line 14, in Wrong
def work(self) -> self.Result2:
NameError: name 'self' is not defined

# Fixed code
def _ignore_class_scope(self, node):
    """
    Return True if the node is in a local class scope, as an assignment.

    :param node: Node considered
    :type node: astroid.Node
    :return: True if the node is in a local class scope, as an assignment. False otherwise.
    :rtype: bool
    """
    # Detect if we are in a local class scope, as an assignment.
    # For example, the following is fair game.
    #
    # class A:
    #    b = 1
    #    c = lambda b=b: b * b
    #
    # class B:
    #    tp = 1
    #    def func(self, arg: tp):
    #        ...
    # class C:
    #    tp = 2
    #    def func(self, arg=tp):
    #        ...
    # class C:
    #    class Tp:
    #        pass
    #    class D(Tp):
    #        ...

    name = node.name
    frame = node.statement().scope()
    in_annotation_or_default_or_decorator = self._defined_in_function_definition(
        node, frame
    )
    in_ancestor_list = utils.is_ancestor_name(frame, node)
    if in_annotation_or_default_or_decorator or in_ancestor_list:
        frame_locals = frame.parent.scope().locals
    else:
        frame_locals = frame.locals
    return not (
        (isinstance(frame, astroid.ClassDef) or in_annotation_or_default_or_decorator)
        and not self._in_lambda_or_comprehension_body(node, frame)
        and name in frame_locals
    )
# Buggy code
def _worker_check_single_file(file_item):
    name, filepath, modname = file_item

    _worker_linter.open()
    _worker_linter.check_single_file(name, filepath, modname)

    msgs = [_get_new_args(m) for m in _worker_linter.reporter.messages]
    return (
        _worker_linter.current_name,
        _worker_linter.file_state.base_name,
        msgs,
        _worker_linter.stats,
        _worker_linter.msg_status,
    )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/bin/pylint", line 8, in <module>
sys.exit(run_pylint())
File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/__init__.py", line 22, in run_pylint
PylintRun(sys.argv[1:])
File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/lint/run.py", line 338, in __init__
linter.check(args)
File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 878, in check
files_or_modules,
File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/lint/check_parallel.py", line 106, in check_parallel
linter.reporter.handle_message(msg)
File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/reporters/text.py", line 151, in handle_message
self.write_message(msg)
File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/reporters/text.py", line 141, in write_message
self.writeln(msg.format(self._template))
File "/opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/lib/python3.6/site-packages/pylint/message/message.py", line 51, in format
return template.format(**dict(zip(self._fields, self)))
AttributeError: 'NoneType' object has no attribute 'format'
ERROR: InvocationError for command /opt/gitlab-runner/NCiG8AGt/0/<path>/.tox/pylint/bin/pylint src/ (exited with code 1)

# Fixed code
def _worker_check_single_file(file_item):
    name, filepath, modname = file_item

    _worker_linter.open()
    _worker_linter.check_single_file(name, filepath, modname)

    msgs = [_get_new_args(m) for m in _worker_linter.reporter.messages]
    return (
        _worker_linter.current_name,
        filepath,
        _worker_linter.file_state.base_name,
        msgs,
        _worker_linter.stats,
        _worker_linter.msg_status,
    )
# Buggy code
def get_values(self, obj):
    """get label and shape for classes.

    The label contains all attributes and methods
    """
    label = obj.title
    if obj.shape == "interface":
        label = "«interface»\\n%s" % label
    if not self.config.only_classnames:
        label = r"%s|%s\l|" % (label, r"\l".join(obj.attrs))
        for func in obj.methods:
            args = [arg.name for arg in func.args.args if arg.name != "self"]
            label = r"%s%s(%s)\l" % (label, func.name, ", ".join(args))
        label = "{%s}" % label
    if is_exception(obj.node):
        return dict(fontcolor="red", label=label, shape="record")
    return dict(label=label, shape="record")


# Traceback (TypeError)
pyreverse -o png -my -f OTHER -S -A -p testuml ~/pyreverse_error.py
...
Traceback (most recent call last):
File "/home/ervthon/venv357/bin/pyreverse", line 11, in <module>
sys.exit(run_pyreverse())
File "/home/ervthon/venv357/lib/python3.5/site-packages/pylint/__init__.py", line 37, in run_pyreverse
PyreverseRun(sys.argv[1:])
File "/home/ervthon/venv357/lib/python3.5/site-packages/pylint/pyreverse/main.py", line 184, in __init__
sys.exit(self.run(args))
File "/home/ervthon/venv357/lib/python3.5/site-packages/pylint/pyreverse/main.py", line 209, in run
writer.DotWriter(self.config).write(diadefs)
File "/home/ervthon/venv357/lib/python3.5/site-packages/pylint/pyreverse/writer.py", line 38, in write
self.write_classes(diagram)
File "/home/ervthon/venv357/lib/python3.5/site-packages/pylint/pyreverse/writer.py", line 59, in write_classes
self.printer.emit_node(i, **self.get_values(obj))
File "/home/ervthon/venv357/lib/python3.5/site-packages/pylint/pyreverse/writer.py", line 134, in get_values
args = [arg.name for arg in func.args.args if arg.name != "self"]
TypeError: 'NoneType' object is not iterable

# Fixed code
def get_values(self, obj):
    """get label and shape for classes.

    The label contains all attributes and methods
    """
    label = obj.title
    if obj.shape == "interface":
        label = "«interface»\\n%s" % label
    if not self.config.only_classnames:
        label = r"%s|%s\l|" % (label, r"\l".join(obj.attrs))
        for func in obj.methods:
            if func.args.args:
                args = [arg.name for arg in func.args.args if arg.name != "self"]
            else:
                args = []
            label = r"%s%s(%s)\l" % (label, func.name, ", ".join(args))
        label = "{%s}" % label
    if is_exception(obj.node):
        return dict(fontcolor="red", label=label, shape="record")
    return dict(label=label, shape="record")
# Buggy code
def _check_redefinition(self, redeftype, node):
    """check for redefinition of a function / method / class name"""
    defined_self = node.parent.frame()[node.name]
    if defined_self is not node and not astroid.are_exclusive(node, defined_self):
        dummy_variables_rgx = lint_utils.get_global_option(
            self, "dummy-variables-rgx", default=None
        )
        if dummy_variables_rgx and dummy_variables_rgx.match(defined_self.name):
            return
        self.add_message(
            "function-redefined", node=node, args=(redeftype, defined_self.fromlineno)
        )


# Traceback (AttributeError)
Traceback (most recent call last):
File "/Users/jacques/miniconda/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/__init__.py", line 16, in run_pylint
Run(sys.argv[1:])
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/lint.py", line 1347, in __init__
linter.check(args)
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/lint.py", line 768, in check
self._do_check(files_or_modules)
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/lint.py", line 901, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/lint.py", line 980, in check_astroid_module
walker.walk(ast_node)
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/utils.py", line 1014, in walk
self.walk(child)
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/utils.py", line 1011, in walk
cb(astroid)
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/checkers/base.py", line 505, in visit_functiondef
self._check_redefinition(node.is_method() and 'method' or 'function', node)
File "/Users/jacques/miniconda/lib/python3.6/site-packages/pylint/checkers/base.py", line 717, in _check_redefinition
if dummy_variables_rgx and dummy_variables_rgx.match(defined_self.name):
AttributeError: 'ImportFrom' object has no attribute 'name'

# Fixed code
def _check_redefinition(self, redeftype, node):
    """check for redefinition of a function / method / class name"""
    defined_self = node.parent.frame()[node.name]
    if defined_self is not node and not astroid.are_exclusive(node, defined_self):
        dummy_variables_rgx = lint_utils.get_global_option(
            self, "dummy-variables-rgx", default=None
        )
        if dummy_variables_rgx and dummy_variables_rgx.match(node.name):
            return
        self.add_message(
            "function-redefined", node=node, args=(redeftype, defined_self.fromlineno)
        )
# Buggy code
def _check_stop_iteration_inside_generator(self, node):
    """Check if an exception of type StopIteration is raised inside a generator"""
    frame = node.frame()
    if not isinstance(frame, astroid.FunctionDef) or not frame.is_generator():
        return
    if utils.node_ignores_exception(node, StopIteration):
        return
    if not node.exc:
        return
    exc = utils.safe_infer(node.exc)
    if exc is not None and self._check_exception_inherit_from_stopiteration(exc):
        self.add_message("stop-iteration-return", node=node)


# Traceback (TypeError)
# pylint test.py
No config file found, using default configuration
Traceback (most recent call last):
File "/usr/local/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/usr/local/lib/python3.6/dist-packages/pylint/__init__.py", line 16, in run_pylint
Run(sys.argv[1:])
File "/usr/local/lib/python3.6/dist-packages/pylint/lint.py", line 1347, in __init__
linter.check(args)
File "/usr/local/lib/python3.6/dist-packages/pylint/lint.py", line 768, in check
self._do_check(files_or_modules)
File "/usr/local/lib/python3.6/dist-packages/pylint/lint.py", line 901, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/usr/local/lib/python3.6/dist-packages/pylint/lint.py", line 980, in check_astroid_module
walker.walk(ast_node)
File "/usr/local/lib/python3.6/dist-packages/pylint/utils.py", line 1014, in walk
self.walk(child)
File "/usr/local/lib/python3.6/dist-packages/pylint/utils.py", line 1014, in walk
self.walk(child)
File "/usr/local/lib/python3.6/dist-packages/pylint/utils.py", line 1011, in walk
cb(astroid)
File "/usr/local/lib/python3.6/dist-packages/pylint/checkers/refactoring.py", line 362, in visit_raise
self._check_stop_iteration_inside_generator(node)
File "/usr/local/lib/python3.6/dist-packages/pylint/checkers/refactoring.py", line 374, in _check_stop_iteration_inside_generator
if exc is not None and self._check_exception_inherit_from_stopiteration(exc):
File "/usr/local/lib/python3.6/dist-packages/pylint/checkers/refactoring.py", line 381, in _check_exception_inherit_from_stopiteration
return any(_class.qname() == stopiteration_qname for _class in exc.mro())
TypeError: 'Uninferable' object is not iterable

# Fixed code
def _check_stop_iteration_inside_generator(self, node):
    """Check if an exception of type StopIteration is raised inside a generator"""
    frame = node.frame()
    if not isinstance(frame, astroid.FunctionDef) or not frame.is_generator():
        return
    if utils.node_ignores_exception(node, StopIteration):
        return
    if not node.exc:
        return
    exc = utils.safe_infer(node.exc)
    if exc is None or exc is astroid.Uninferable:
        return
    if self._check_exception_inherit_from_stopiteration(exc):
        self.add_message("stop-iteration-return", node=node)
# Buggy code
def __init__(self, linter=None):
    BaseChecker.__init__(self, linter)
    self._accessed = []
    self._first_attrs = []
    self._meth_could_be_func = None


# Traceback (IndexError)
No config file found, using default configuration
************* Module pylint_bug
C:  1, 0: Missing module docstring (missing-docstring)
C:  1, 0: Missing class docstring (missing-docstring)
C:  2,10: Missing method docstring (missing-docstring)
R:  1, 0: Too few public methods (1/2) (too-few-public-methods)
C:  6, 0: Missing function docstring (missing-docstring)
Traceback (most recent call last):
File "/tmp/test_pylint/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/__init__.py", line 13, in run_pylint
Run(sys.argv[1:])
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 1310, in __init__
linter.check(args)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 732, in check
self._do_check(files_or_modules)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 863, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 944, in check_astroid_module
walker.walk(ast_node)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 941, in walk
cb(astroid)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/checkers/classes.py", line 578, in visit_attribute
self._accessed[-1][attrname].append(node)
IndexError: list index out of range

# Fixed code
def __init__(self, linter=None):
    BaseChecker.__init__(self, linter)
    self._accessed = ScopeAccessMap()
    self._first_attrs = []
    self._meth_could_be_func = None
# Buggy code
def visit_classdef(self, node):
    """init visit variable _accessed"""
    self._accessed.append(defaultdict(list))
    self._check_bases_classes(node)
    # if not an exception or a metaclass
    if node.type == "class" and has_known_bases(node):
        try:
            node.local_attr("__init__")
        except astroid.NotFoundError:
            self.add_message("no-init", args=node, node=node)
    self._check_slots(node)
    self._check_proper_bases(node)
    self._check_consistent_mro(node)


# Traceback (IndexError)
No config file found, using default configuration
************* Module pylint_bug
C:  1, 0: Missing module docstring (missing-docstring)
C:  1, 0: Missing class docstring (missing-docstring)
C:  2,10: Missing method docstring (missing-docstring)
R:  1, 0: Too few public methods (1/2) (too-few-public-methods)
C:  6, 0: Missing function docstring (missing-docstring)
Traceback (most recent call last):
File "/tmp/test_pylint/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/__init__.py", line 13, in run_pylint
Run(sys.argv[1:])
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 1310, in __init__
linter.check(args)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 732, in check
self._do_check(files_or_modules)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 863, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 944, in check_astroid_module
walker.walk(ast_node)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 941, in walk
cb(astroid)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/checkers/classes.py", line 578, in visit_attribute
self._accessed[-1][attrname].append(node)
IndexError: list index out of range

# Fixed code
def visit_classdef(self, node):
    """init visit variable _accessed"""
    self._check_bases_classes(node)
    # if not an exception or a metaclass
    if node.type == "class" and has_known_bases(node):
        try:
            node.local_attr("__init__")
        except astroid.NotFoundError:
            self.add_message("no-init", args=node, node=node)
    self._check_slots(node)
    self._check_proper_bases(node)
    self._check_consistent_mro(node)
# Buggy code
def visit_attribute(self, node):
    """check if the getattr is an access to a class member
    if so, register it. Also check for access to protected
    class member from outside its class (but ignore __special__
    methods)
    """
    attrname = node.attrname
    # Check self
    if self.is_first_attr(node):
        self._accessed[-1][attrname].append(node)
        return
    if not self.linter.is_message_enabled("protected-access"):
        return

    self._check_protected_attribute_access(node)


# Traceback (IndexError)
No config file found, using default configuration
************* Module pylint_bug
C:  1, 0: Missing module docstring (missing-docstring)
C:  1, 0: Missing class docstring (missing-docstring)
C:  2,10: Missing method docstring (missing-docstring)
R:  1, 0: Too few public methods (1/2) (too-few-public-methods)
C:  6, 0: Missing function docstring (missing-docstring)
Traceback (most recent call last):
File "/tmp/test_pylint/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/__init__.py", line 13, in run_pylint
Run(sys.argv[1:])
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 1310, in __init__
linter.check(args)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 732, in check
self._do_check(files_or_modules)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 863, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 944, in check_astroid_module
walker.walk(ast_node)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 941, in walk
cb(astroid)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/checkers/classes.py", line 578, in visit_attribute
self._accessed[-1][attrname].append(node)
IndexError: list index out of range

# Fixed code
def visit_attribute(self, node):
    """check if the getattr is an access to a class member
    if so, register it. Also check for access to protected
    class member from outside its class (but ignore __special__
    methods)
    """
    # Check self
    if self.is_first_attr(node):
        self._accessed.set_accessed(node)
        return
    if not self.linter.is_message_enabled("protected-access"):
        return

    self._check_protected_attribute_access(node)
# Buggy code
def visit_assignattr(self, node):
    if isinstance(node.assign_type(), astroid.AugAssign) and self.is_first_attr(node):
        self._accessed[-1][node.attrname].append(node)
    self._check_in_slots(node)


# Traceback (IndexError)
No config file found, using default configuration
************* Module pylint_bug
C:  1, 0: Missing module docstring (missing-docstring)
C:  1, 0: Missing class docstring (missing-docstring)
C:  2,10: Missing method docstring (missing-docstring)
R:  1, 0: Too few public methods (1/2) (too-few-public-methods)
C:  6, 0: Missing function docstring (missing-docstring)
Traceback (most recent call last):
File "/tmp/test_pylint/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/__init__.py", line 13, in run_pylint
Run(sys.argv[1:])
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 1310, in __init__
linter.check(args)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 732, in check
self._do_check(files_or_modules)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 863, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/lint.py", line 944, in check_astroid_module
walker.walk(ast_node)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 944, in walk
self.walk(child)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/utils.py", line 941, in walk
cb(astroid)
File "/private/tmp/test_pylint/lib/python3.5/site-packages/pylint/checkers/classes.py", line 578, in visit_attribute
self._accessed[-1][attrname].append(node)
IndexError: list index out of range

# Fixed code
def visit_assignattr(self, node):
    if isinstance(node.assign_type(), astroid.AugAssign) and self.is_first_attr(node):
        self._accessed.set_accessed(node)
    self._check_in_slots(node)
# Buggy code
def fromtimestamp(cls, timestamp, tzinfo=None):
    """Constructs an :class:`Arrow <arrow.arrow.Arrow>` object from a timestamp, converted to
    the given timezone.

    :param timestamp: an ``int`` or ``float`` timestamp, or a ``str`` that converts to either.
    :param tzinfo: (optional) a ``tzinfo`` object.  Defaults to local time.
    """

    if tzinfo is None:
        tzinfo = dateutil_tz.tzlocal()
    elif util.isstr(tzinfo):
        tzinfo = parser.TzinfoParser.parse(tzinfo)

    if not util.is_timestamp(timestamp):
        raise ValueError("The provided timestamp '{}' is invalid.".format(timestamp))

    dt = datetime.fromtimestamp(float(timestamp), tzinfo)

    return cls(
        dt.year,
        dt.month,
        dt.day,
        dt.hour,
        dt.minute,
        dt.second,
        dt.microsecond,
        dt.tzinfo,
    )


# Traceback (ValueError)
arrow.get(1590889920000.0).timestamp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/api.py", line 21, in get
return _factory.get(*args, **kwargs)
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/factory.py", line 176, in get
return self.type.fromtimestamp(arg, tzinfo=tz)
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/arrow.py", line 161, in fromtimestamp
dt = datetime.fromtimestamp(float(timestamp), tzinfo)
ValueError: year 52383 is out of range

# Fixed code
def fromtimestamp(cls, timestamp, tzinfo=None):
    """Constructs an :class:`Arrow <arrow.arrow.Arrow>` object from a timestamp, converted to
    the given timezone.

    :param timestamp: an ``int`` or ``float`` timestamp, or a ``str`` that converts to either.
    :param tzinfo: (optional) a ``tzinfo`` object.  Defaults to local time.
    """

    if tzinfo is None:
        tzinfo = dateutil_tz.tzlocal()
    elif util.isstr(tzinfo):
        tzinfo = parser.TzinfoParser.parse(tzinfo)

    if not util.is_timestamp(timestamp):
        raise ValueError("The provided timestamp '{}' is invalid.".format(timestamp))

    timestamp = util.normalize_timestamp(float(timestamp))
    dt = datetime.fromtimestamp(timestamp, tzinfo)

    return cls(
        dt.year,
        dt.month,
        dt.day,
        dt.hour,
        dt.minute,
        dt.second,
        dt.microsecond,
        dt.tzinfo,
    )
# Buggy code
def utcfromtimestamp(cls, timestamp):
    """Constructs an :class:`Arrow <arrow.arrow.Arrow>` object from a timestamp, in UTC time.

    :param timestamp: an ``int`` or ``float`` timestamp, or a ``str`` that converts to either.

    """

    if not util.is_timestamp(timestamp):
        raise ValueError("The provided timestamp '{}' is invalid.".format(timestamp))

    dt = datetime.utcfromtimestamp(float(timestamp))

    return cls(
        dt.year,
        dt.month,
        dt.day,
        dt.hour,
        dt.minute,
        dt.second,
        dt.microsecond,
        dateutil_tz.tzutc(),
    )


# Traceback (ValueError)
arrow.get(1590889920000.0).timestamp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/api.py", line 21, in get
return _factory.get(*args, **kwargs)
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/factory.py", line 176, in get
return self.type.fromtimestamp(arg, tzinfo=tz)
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/arrow.py", line 161, in fromtimestamp
dt = datetime.fromtimestamp(float(timestamp), tzinfo)
ValueError: year 52383 is out of range

# Fixed code
def utcfromtimestamp(cls, timestamp):
    """Constructs an :class:`Arrow <arrow.arrow.Arrow>` object from a timestamp, in UTC time.

    :param timestamp: an ``int`` or ``float`` timestamp, or a ``str`` that converts to either.

    """

    if not util.is_timestamp(timestamp):
        raise ValueError("The provided timestamp '{}' is invalid.".format(timestamp))

    timestamp = util.normalize_timestamp(float(timestamp))
    dt = datetime.utcfromtimestamp(timestamp)

    return cls(
        dt.year,
        dt.month,
        dt.day,
        dt.hour,
        dt.minute,
        dt.second,
        dt.microsecond,
        dateutil_tz.tzutc(),
    )
# Buggy code
def is_timestamp(value):
    """Check if value is a valid timestamp."""
    if isinstance(value, bool):
        return False
    if not (
        isinstance(value, int) or isinstance(value, float) or isinstance(value, str)
    ):
        return False
    try:
        float(value)
        return True
    except ValueError:
        return False


# Traceback (ValueError)
arrow.get(1590889920000.0).timestamp
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/api.py", line 21, in get
return _factory.get(*args, **kwargs)
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/factory.py", line 176, in get
return self.type.fromtimestamp(arg, tzinfo=tz)
File "/Users/charlie/Library/Python/3.7/lib/python/site-packages/arrow/arrow.py", line 161, in fromtimestamp
dt = datetime.fromtimestamp(float(timestamp), tzinfo)
ValueError: year 52383 is out of range

# Fixed code
def is_timestamp(value):
    """Check if value is a valid timestamp."""
    if isinstance(value, bool):
        return False
    if not (
        isinstance(value, numbers.Integral)
        or isinstance(value, float)
        or isinstance(value, str)
    ):
        return False
    try:
        float(value)
        return True
    except ValueError:
        return False
# Buggy code
def build_embeddings(opt, word_field, feat_fields, for_encoder=True):
    """
    Args:
        opt: the option in current environment.
        word_dict(Vocab): words dictionary.
        feature_dicts([Vocab], optional): a list of feature dictionary.
        for_encoder(bool): build Embeddings for encoder or decoder?
    """
    emb_dim = opt.src_word_vec_size if for_encoder else opt.tgt_word_vec_size

    word_padding_idx = word_field.vocab.stoi[word_field.pad_token]
    num_word_embeddings = len(word_field.vocab)

    feat_pad_indices = [ff.vocab.stoi[ff.pad_token] for ff in feat_fields]
    num_feat_embeddings = [len(ff.vocab) for ff in feat_fields]

    emb = Embeddings(
        word_vec_size=emb_dim,
        position_encoding=opt.position_encoding,
        feat_merge=opt.feat_merge,
        feat_vec_exponent=opt.feat_vec_exponent,
        feat_vec_size=opt.feat_vec_size,
        dropout=opt.dropout,
        word_padding_idx=word_padding_idx,
        feat_padding_idx=feat_pad_indices,
        word_vocab_size=num_word_embeddings,
        feat_vocab_sizes=num_feat_embeddings,
        sparse=opt.optim == "sparseadam",
    )
    return emb


# Traceback (ValueError)
Traceback (most recent call last):
File "train.py", line 40, in <module>
main(opt)
File "train.py", line 27, in main
single_main(opt)
File "/home/rudra/OpenNMT-py/onmt/train_single.py", line 113, in main
optim = build_optim(model, opt, checkpoint)
File "/home/rudra/OpenNMT-py/onmt/utils/optimizers.py", line 62, in build_optim
optim.optimizer.load_state_dict(saved_optimizer_state_dict)
File "/home/rudra/miniconda3/envs/py36/lib/python3.6/site-packages/torch/optim/optimizer.py", line         107, in load_state_dict
raise ValueError("loaded state dict contains a parameter group "
ValueError: loaded state dict contains a parameter group that doesn't match the size of optimizer's group

# Fixed code
def build_embeddings(opt, word_field, feat_fields, for_encoder=True):
    """
    Args:
        opt: the option in current environment.
        word_dict(Vocab): words dictionary.
        feature_dicts([Vocab], optional): a list of feature dictionary.
        for_encoder(bool): build Embeddings for encoder or decoder?
    """
    emb_dim = opt.src_word_vec_size if for_encoder else opt.tgt_word_vec_size

    word_padding_idx = word_field.vocab.stoi[word_field.pad_token]
    num_word_embeddings = len(word_field.vocab)

    feat_pad_indices = [ff.vocab.stoi[ff.pad_token] for ff in feat_fields]
    num_feat_embeddings = [len(ff.vocab) for ff in feat_fields]

    fix_word_vecs = opt.fix_word_vecs_enc if for_encoder else opt.fix_word_vecs_dec

    emb = Embeddings(
        word_vec_size=emb_dim,
        position_encoding=opt.position_encoding,
        feat_merge=opt.feat_merge,
        feat_vec_exponent=opt.feat_vec_exponent,
        feat_vec_size=opt.feat_vec_size,
        dropout=opt.dropout,
        word_padding_idx=word_padding_idx,
        feat_padding_idx=feat_pad_indices,
        word_vocab_size=num_word_embeddings,
        feat_vocab_sizes=num_feat_embeddings,
        sparse=opt.optim == "sparseadam",
        fix_word_vecs=fix_word_vecs,
    )
    return emb
# Buggy code
def load_pretrained_vectors(self, emb_file, fixed):
    """Load in pretrained embeddings.

    Args:
      emb_file (str) : path to torch serialized embeddings
      fixed (bool) : if true, embeddings are not updated
    """
    if emb_file:
        pretrained = torch.load(emb_file)
        pretrained_vec_size = pretrained.size(1)
        if self.word_vec_size > pretrained_vec_size:
            self.word_lut.weight.data[:, :pretrained_vec_size] = pretrained
        elif self.word_vec_size < pretrained_vec_size:
            self.word_lut.weight.data.copy_(pretrained[:, : self.word_vec_size])
        else:
            self.word_lut.weight.data.copy_(pretrained)
        if fixed:
            self.word_lut.weight.requires_grad = False


# Traceback (ValueError)
Traceback (most recent call last):
File "train.py", line 40, in <module>
main(opt)
File "train.py", line 27, in main
single_main(opt)
File "/home/rudra/OpenNMT-py/onmt/train_single.py", line 113, in main
optim = build_optim(model, opt, checkpoint)
File "/home/rudra/OpenNMT-py/onmt/utils/optimizers.py", line 62, in build_optim
optim.optimizer.load_state_dict(saved_optimizer_state_dict)
File "/home/rudra/miniconda3/envs/py36/lib/python3.6/site-packages/torch/optim/optimizer.py", line         107, in load_state_dict
raise ValueError("loaded state dict contains a parameter group "
ValueError: loaded state dict contains a parameter group that doesn't match the size of optimizer's group

# Fixed code
def load_pretrained_vectors(self, emb_file):
    """Load in pretrained embeddings.

    Args:
      emb_file (str) : path to torch serialized embeddings
      fixed (bool) : if true, embeddings are not updated
    """
    if emb_file:
        pretrained = torch.load(emb_file)
        pretrained_vec_size = pretrained.size(1)
        if self.word_vec_size > pretrained_vec_size:
            self.word_lut.weight.data[:, :pretrained_vec_size] = pretrained
        elif self.word_vec_size < pretrained_vec_size:
            self.word_lut.weight.data.copy_(pretrained[:, : self.word_vec_size])
        else:
            self.word_lut.weight.data.copy_(pretrained)