gurudesh/pytracebugs huggingface dataset:
# Buggy code
def copy(self):
    s = Node(self.name, self.data)
    for c in self.children:
        c = c.copy()
        s.add_child(c)
    return s


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
/home/a000680/laptop/Pytroll/demo/modis/satpy_issue_5march2018.py in <module>()
59
60 scn.load(['solar_azimuth_angle', 'solar_zenith_angle',
---> 61           'satellite_zenith_angle', 'satellite_azimuth_angle'], resolution=1000)

/home/a000680/usr/src/satpy/satpy/scene.pyc in load(self, wishlist, calibration, resolution, polarization, compute, unload, **kwargs)
639             raise KeyError("Unknown datasets: {}".format(unknown_str))
640
--> 641         self.read(**kwargs)
642         keepables = None
643         if compute:

/home/a000680/usr/src/satpy/satpy/scene.pyc in read(self, nodes, **kwargs)
580             required_nodes = self.wishlist - set(self.datasets.keys())
581             nodes = self.dep_tree.leaves(nodes=required_nodes)
--> 582         return self.read_datasets(nodes, **kwargs)
583
584     def compute(self, nodes=None):

/home/a000680/usr/src/satpy/satpy/scene.pyc in read_datasets(self, dataset_nodes, **kwargs)
443             if ds_id in self.datasets and self.datasets[ds_id].is_loaded():
444                 continue
--> 445             reader_name = node.data['reader_name']
446             reader_datasets.setdefault(reader_name, set()).add(ds_id)
447

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def copy(self, node_cache=None):
    if node_cache and self.name in node_cache:
        return node_cache[self.name]

    s = Node(self.name, self.data)
    for c in self.children:
        c = c.copy(node_cache=node_cache)
        s.add_child(c)
    return s
# Buggy code
def copy(self):
    """Copy the this node tree

    Note all references to readers are removed. This is meant to avoid
    tree copies accessing readers that would return incompatible (Area)
    data. Theoretically it should be possible for tree copies to request
    compositor or modifier information as long as they don't depend on
    any datasets not already existing in the dependency tree.
    """
    new_tree = DependencyTree({}, self.compositors, self.modifiers)
    for c in self.children:
        c = c.copy()
        new_tree.add_child(new_tree, c)
    new_tree._all_nodes = new_tree.flatten(d=self._all_nodes)
    return new_tree


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
/home/a000680/laptop/Pytroll/demo/modis/satpy_issue_5march2018.py in <module>()
59
60 scn.load(['solar_azimuth_angle', 'solar_zenith_angle',
---> 61           'satellite_zenith_angle', 'satellite_azimuth_angle'], resolution=1000)

/home/a000680/usr/src/satpy/satpy/scene.pyc in load(self, wishlist, calibration, resolution, polarization, compute, unload, **kwargs)
639             raise KeyError("Unknown datasets: {}".format(unknown_str))
640
--> 641         self.read(**kwargs)
642         keepables = None
643         if compute:

/home/a000680/usr/src/satpy/satpy/scene.pyc in read(self, nodes, **kwargs)
580             required_nodes = self.wishlist - set(self.datasets.keys())
581             nodes = self.dep_tree.leaves(nodes=required_nodes)
--> 582         return self.read_datasets(nodes, **kwargs)
583
584     def compute(self, nodes=None):

/home/a000680/usr/src/satpy/satpy/scene.pyc in read_datasets(self, dataset_nodes, **kwargs)
443             if ds_id in self.datasets and self.datasets[ds_id].is_loaded():
444                 continue
--> 445             reader_name = node.data['reader_name']
446             reader_datasets.setdefault(reader_name, set()).add(ds_id)
447

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def copy(self):
    """Copy the this node tree

    Note all references to readers are removed. This is meant to avoid
    tree copies accessing readers that would return incompatible (Area)
    data. Theoretically it should be possible for tree copies to request
    compositor or modifier information as long as they don't depend on
    any datasets not already existing in the dependency tree.
    """
    new_tree = DependencyTree({}, self.compositors, self.modifiers)
    for c in self.children:
        c = c.copy(node_cache=new_tree._all_nodes)
        new_tree.add_child(new_tree, c)
    return new_tree
# Buggy code
def read(self, nodes=None, **kwargs):
    """Load datasets from the necessary reader.

    Args:
        nodes (iterable): DependencyTree Node objects
        **kwargs: Keyword arguments to pass to the reader's `load` method.

    Returns:
        DatasetDict of loaded datasets

    """
    if nodes is None:
        required_nodes = self.wishlist - set(self.datasets.keys())
        nodes = self.dep_tree.leaves(nodes=required_nodes)
    return self.read_datasets(nodes, **kwargs)


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
/home/a000680/laptop/Pytroll/demo/modis/satpy_issue_5march2018.py in <module>()
59
60 scn.load(['solar_azimuth_angle', 'solar_zenith_angle',
---> 61           'satellite_zenith_angle', 'satellite_azimuth_angle'], resolution=1000)

/home/a000680/usr/src/satpy/satpy/scene.pyc in load(self, wishlist, calibration, resolution, polarization, compute, unload, **kwargs)
639             raise KeyError("Unknown datasets: {}".format(unknown_str))
640
--> 641         self.read(**kwargs)
642         keepables = None
643         if compute:

/home/a000680/usr/src/satpy/satpy/scene.pyc in read(self, nodes, **kwargs)
580             required_nodes = self.wishlist - set(self.datasets.keys())
581             nodes = self.dep_tree.leaves(nodes=required_nodes)
--> 582         return self.read_datasets(nodes, **kwargs)
583
584     def compute(self, nodes=None):

/home/a000680/usr/src/satpy/satpy/scene.pyc in read_datasets(self, dataset_nodes, **kwargs)
443             if ds_id in self.datasets and self.datasets[ds_id].is_loaded():
444                 continue
--> 445             reader_name = node.data['reader_name']
446             reader_datasets.setdefault(reader_name, set()).add(ds_id)
447

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def read(self, nodes=None, **kwargs):
    """Load datasets from the necessary reader.

    Args:
        nodes (iterable): DependencyTree Node objects
        **kwargs: Keyword arguments to pass to the reader's `load` method.

    Returns:
        DatasetDict of loaded datasets

    """
    if nodes is None:
        required_nodes = self.wishlist - set(self.datasets.keys())
        nodes = self.dep_tree.leaves(nodes=required_nodes)
    return self._read_datasets(nodes, **kwargs)
# Buggy code
def compute(self, nodes=None):
    """Compute all the composites contained in `requirements`."""
    if nodes is None:
        required_nodes = self.wishlist - set(self.datasets.keys())
        nodes = set(self.dep_tree.trunk(nodes=required_nodes)) - set(
            self.datasets.keys()
        )
    return self.read_composites(nodes)


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
/home/a000680/laptop/Pytroll/demo/modis/satpy_issue_5march2018.py in <module>()
59
60 scn.load(['solar_azimuth_angle', 'solar_zenith_angle',
---> 61           'satellite_zenith_angle', 'satellite_azimuth_angle'], resolution=1000)

/home/a000680/usr/src/satpy/satpy/scene.pyc in load(self, wishlist, calibration, resolution, polarization, compute, unload, **kwargs)
639             raise KeyError("Unknown datasets: {}".format(unknown_str))
640
--> 641         self.read(**kwargs)
642         keepables = None
643         if compute:

/home/a000680/usr/src/satpy/satpy/scene.pyc in read(self, nodes, **kwargs)
580             required_nodes = self.wishlist - set(self.datasets.keys())
581             nodes = self.dep_tree.leaves(nodes=required_nodes)
--> 582         return self.read_datasets(nodes, **kwargs)
583
584     def compute(self, nodes=None):

/home/a000680/usr/src/satpy/satpy/scene.pyc in read_datasets(self, dataset_nodes, **kwargs)
443             if ds_id in self.datasets and self.datasets[ds_id].is_loaded():
444                 continue
--> 445             reader_name = node.data['reader_name']
446             reader_datasets.setdefault(reader_name, set()).add(ds_id)
447

TypeError: 'NoneType' object has no attribute '__getitem__'

# Fixed code
def compute(self, nodes=None):
    """Compute all the composites contained in `requirements`."""
    if nodes is None:
        required_nodes = self.wishlist - set(self.datasets.keys())
        nodes = set(self.dep_tree.trunk(nodes=required_nodes)) - set(
            self.datasets.keys()
        )
    return self._read_composites(nodes)
# Buggy code
def clean_percentage(self):
    if not self.range:
        raise exceptions.ValidationError(
            _("Percentage benefits require a product range")
        )
    if self.value > 100:
        raise exceptions.ValidationError(
            _("Percentage discount cannot be greater than 100")
        )


# Traceback (TypeError)
Traceback (most recent call last):
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 30, in inner
return func(*args, **kwds)
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/a1/projects/djangooscar/src/oscar/apps/dashboard/offers/views.py", line 93, in dispatch
**kwargs)
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/views/generic/edit.py", line 221, in post
if form.is_valid():
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/forms/forms.py", line 161, in is_valid
return self.is_bound and not self.errors
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/forms/forms.py", line 153, in errors
self.full_clean()
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/forms/forms.py", line 364, in full_clean
self._post_clean()
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/forms/models.py", line 396, in _post_clean
self.instance.full_clean(exclude=exclude, validate_unique=False)
File "/Users/a1/projects/djangooscar/env3/lib/python3.5/site-packages/django/db/models/base.py", line 1129, in full_clean
self.clean()
File "/Users/a1/projects/djangooscar/src/oscar/apps/offer/abstract_models.py", line 497, in clean
getattr(self, method_name)()
File "/Users/a1/projects/djangooscar/src/oscar/apps/offer/abstract_models.py", line 515, in clean_percentage
if self.value > 100:
TypeError: unorderable types: NoneType() > int()

# Fixed code
def clean_percentage(self):
    if not self.range:
        raise exceptions.ValidationError(
            _("Percentage benefits require a product range")
        )
    if not self.value:
        raise exceptions.ValidationError(
            _("Percentage discount benefits require a value")
        )
    if self.value > 100:
        raise exceptions.ValidationError(
            _("Percentage discount cannot be greater than 100")
        )
# Buggy code
def lookup(self, name, table="monster"):
    """Looks up a monster, technique, item, or npc based on name or id.

    :param name: The name of the monster, technique, item, or npc.
    :param table: Which index to do the search in. Can be: "monster",
        "item", "npc", or "technique".
    :type name: String
    :type table: String

    :rtype: Dict
    :returns: A dictionary from the resulting lookup.

    """
    if name in self.database[table]:
        return self.database[table][name]

    for id, item in self.database[table].items():
        if item["name"] == name:
            return item


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def lookup(self, slug, table="monster"):
    """Looks up a monster, technique, item, or npc based on name or id.

    :param slug: The slug of the monster, technique, item, or npc.  A short English identifier.
    :param table: Which index to do the search in. Can be: "monster",
        "item", "npc", or "technique".
    :type slug: String
    :type table: String

    :rtype: Dict
    :returns: A dictionary from the resulting lookup.

    """
    if slug in self.database[table]:
        return self.database[table][slug]

    for id, item in self.database[table].items():
        # TODO: localize *everything*
        # the slug lookup will fail for monsters and npc's
        # eventually, we may want to localize monster names or npc
        # in that case, all DB objects will have a slug
        # for now, we silently fail and lookup by name instead
        try:
            if item["slug"] == slug:
                return item
        except KeyError:
            if item["name"] == slug:
                return item
# Buggy code
def __init__(self, name=None, id=None):
    self.id = 0
    self.name = "Blank"
    self.description = "None"
    self.effect = []
    self.type = None
    self.power = 0
    self.sprite = ""  # The path to the sprite to load.
    self.surface = None  # The pygame.Surface object of the item.
    self.surface_size_original = (
        0,
        0,
    )  # The original size of the image before scaling.

    # If a name of the item was provided, autoload it from the item database.
    if name or id:
        self.load(name, id)


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def __init__(self, slug=None, id=None):
    self.id = 0
    self.name = "Blank"
    self.description = "None"
    self.effect = []
    self.type = None
    self.power = 0
    self.sprite = ""  # The path to the sprite to load.
    self.surface = None  # The pygame.Surface object of the item.
    self.surface_size_original = (
        0,
        0,
    )  # The original size of the image before scaling.

    # If a slug of the item was provided, autoload it from the item database.
    if slug or id:
        self.load(slug, id)
# Buggy code
def heal(self, user, target):
    """This effect heals the target based on the item's power attribute.

    :param user: The monster or object that is using this item.
    :param target: The monster or object that we are using this item on.

    :type user: Varies
    :type target: Varies

    :rtype: bool
    :returns: Success

    **Examples:**
    >>> potion_item = Item("Potion")
    >>> potion_item.heal(bulbatux, game)
    """

    if target.current_hp == target.hp:
        return False
    # Heal the target monster by "self.power" number of hitpoints.
    target.current_hp += self.power

    # If we've exceeded the monster's maximum HP, set their health to 100% of their HP.
    if target.current_hp > target.hp:
        target.current_hp = target.hp

    return True


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def heal(self, user, target):
    """This effect heals the target based on the item's power attribute.

    :param user: The monster or object that is using this item.
    :param target: The monster or object that we are using this item on.

    :type user: Varies
    :type target: Varies

    :rtype: bool
    :returns: Success

    **Examples:**
    >>> potion_item = Item("item_potion")
    >>> potion_item.heal(bulbatux, game)
    """

    if target.current_hp == target.hp:
        return False
    # Heal the target monster by "self.power" number of hitpoints.
    target.current_hp += self.power

    # If we've exceeded the monster's maximum HP, set their health to 100% of their HP.
    if target.current_hp > target.hp:
        target.current_hp = target.hp

    return True
# Buggy code
def __init__(self, name=None, id=None):
    self.name = "Pound"
    self.tech_id = 0
    self.category = "attack"
    self.type1 = "Normal"
    self.type2 = None
    self._combat_counter = 0  # number of turns that this technique has been active
    self.power = 1
    self.effect = []

    # If a name of the technique was provided, autoload it.
    if name or id:
        self.load(name, id)


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def __init__(self, slug=None, id=None):
    self.name = "Pound"
    self.tech_id = 0
    self.category = "attack"
    self.type1 = "Normal"
    self.type2 = None
    self._combat_counter = 0  # number of turns that this technique has been active
    self.power = 1
    self.effect = []

    # If a slug of the technique was provided, autoload it.
    if slug or id:
        self.load(slug, id)
# Buggy code
def poison(self, user, target):
    """This effect has a chance to apply the poison status effect to a target monster.
    Currently there is a 1/10 chance of poison.

    :param user: The core.components.monster.Monster object that used this technique.
    :param target: The core.components.monster.Monster object that we are using this
        technique on.

    :type user: core.components.monster.Monster
    :type target: core.components.monster.Monster

    :rtype: bool
    """
    already_poisoned = any(t for t in target.status if t.name == "Poison")

    if not already_poisoned and random.randrange(1, 2) == 1:
        target.apply_status(Technique("Poison"))
        return True

    return False


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def poison(self, user, target):
    """This effect has a chance to apply the poison status effect to a target monster.
    Currently there is a 1/10 chance of poison.

    :param user: The core.components.monster.Monster object that used this technique.
    :param target: The core.components.monster.Monster object that we are using this
        technique on.

    :type user: core.components.monster.Monster
    :type target: core.components.monster.Monster

    :rtype: bool
    """
    already_poisoned = any(t for t in target.status if t.slug == "status_poison")

    if not already_poisoned and random.randrange(1, 2) == 1:
        target.apply_status(Technique("status_poison"))
        return True

    return False
# Buggy code
def faint(self, user, target):
    """Faint this monster.  Typically, called by combat to faint self, not others.

    :param user: The core.components.monster.Monster object that used this technique.
    :param target: The core.components.monster.Monster object that we are using this
        technique on.

    :type user: core.components.monster.Monster
    :type target: core.components.monster.Monster

    :rtype: bool
    """
    already_fainted = any(t for t in target.status if t.name == "Faint")

    if already_fainted:
        raise RuntimeError
    else:
        target.apply_status(Technique("Faint"))
        return True


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def faint(self, user, target):
    """Faint this monster.  Typically, called by combat to faint self, not others.

    :param user: The core.components.monster.Monster object that used this technique.
    :param target: The core.components.monster.Monster object that we are using this
        technique on.

    :type user: core.components.monster.Monster
    :type target: core.components.monster.Monster

    :rtype: bool
    """
    already_fainted = any(t for t in target.status if t.name == "status_faint")

    if already_fainted:
        raise RuntimeError
    else:
        target.apply_status(Technique("status_faint"))
        return True
# Buggy code
def check_status(monster, status_name):
    return any(t for t in monster.status if t.name == status_name)


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def check_status(monster, status_name):
    return any(t for t in monster.status if t.slug == status_name)
# Buggy code
def fainted(monster):
    return check_status(monster, "Faint")


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def fainted(monster):
    return check_status(monster, "status_faint")
# Buggy code
def check_party_hp(self):
    """Apply status effects, then check HP, and party status

    * Monsters will be removed from play here

    :returns: None
    """
    for player in self.monsters_in_play.keys():
        for monster in self.monsters_in_play[player]:
            self.animate_hp(monster)
            if monster.current_hp <= 0 and faint not in monster.status:
                self.remove_monster_actions_from_queue(monster)
                self.faint_monster(monster)


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def check_party_hp(self):
    """Apply status effects, then check HP, and party status

    * Monsters will be removed from play here

    :returns: None
    """
    for player in self.monsters_in_play.keys():
        for monster in self.monsters_in_play[player]:
            self.animate_hp(monster)
            if monster.current_hp <= 0 and not fainted(monster):
                self.remove_monster_actions_from_queue(monster)
                self.faint_monster(monster)
# Buggy code
def swap_it(menuitem):
    monster = menuitem.game_object
    trans = translator.translate
    if monster in self.game.get_state_name("CombatState").active_monsters:
        tools.open_dialog(self.game, [trans("combat_isactive", {"name": monster.name})])
        return
    elif monster.current_hp < 1:
        tools.open_dialog(self.game, [trans("combat_fainted", {"name": monster.name})])
    player = self.game.player1
    target = player.monsters[0]
    swap = Technique("Swap")
    swap.other = monster
    combat_state = self.game.get_state_name("CombatState")
    combat_state.enqueue_action(player, swap, target)
    self.game.pop_state()  # close technique menu
    self.game.pop_state()  # close the monster action menu


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def swap_it(menuitem):
    monster = menuitem.game_object
    trans = translator.translate
    if monster in self.game.get_state_name("CombatState").active_monsters:
        tools.open_dialog(self.game, [trans("combat_isactive", {"name": monster.name})])
        return
    elif monster.current_hp < 1:
        tools.open_dialog(self.game, [trans("combat_fainted", {"name": monster.name})])
    player = self.game.player1
    target = player.monsters[0]
    swap = Technique("technique_swap")
    swap.other = monster
    combat_state = self.game.get_state_name("CombatState")
    combat_state.enqueue_action(player, swap, target)
    self.game.pop_state()  # close technique menu
    self.game.pop_state()  # close the monster action menu
# Buggy code
def choose_technique():
    # open menu to choose technique
    menu = self.game.push_state("Menu")
    menu.shrink_to_items = True

    # add techniques to the menu
    for tech in self.monster.moves:
        image = self.shadow_text(tech.name_trans)
        item = MenuItem(image, None, None, tech)
        menu.add(item)

    # position the new menu
    menu.anchor("bottom", self.rect.top)
    menu.anchor("right", self.game.screen.get_rect().right)

    # set next menu after after selection is made
    menu.on_menu_selection = choose_target


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def choose_technique():
    # open menu to choose technique
    menu = self.game.push_state("Menu")
    menu.shrink_to_items = True

    # add techniques to the menu
    for tech in self.monster.moves:
        image = self.shadow_text(tech.name)
        item = MenuItem(image, None, None, tech)
        menu.add(item)

    # position the new menu
    menu.anchor("bottom", self.rect.top)
    menu.anchor("right", self.game.screen.get_rect().right)

    # set next menu after after selection is made
    menu.on_menu_selection = choose_target
# Buggy code
def on_menu_selection(self, menu_item):
    """Called when player has selected something from the inventory

    Currently, opens a new menu depending on the state context

    :param menu_item:
    :return:
    """
    item = menu_item.game_object
    state = self.determine_state_called_from()

    if state in item.usable_in:
        self.open_confirm_use_menu(item)
    else:
        msg = trans("item_cannot_use_here", {"name": item.name_trans})
        tools.open_dialog(self.game, [msg])


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def on_menu_selection(self, menu_item):
    """Called when player has selected something from the inventory

    Currently, opens a new menu depending on the state context

    :param menu_item:
    :return:
    """
    item = menu_item.game_object
    state = self.determine_state_called_from()

    if state in item.usable_in:
        self.open_confirm_use_menu(item)
    else:
        msg = trans("item_cannot_use_here", {"name": item.name})
        tools.open_dialog(self.game, [msg])
# Buggy code
def initialize_items(self):
    """Get all player inventory items and add them to menu

    :return:
    """
    for name, properties in self.game.player1.inventory.items():
        obj = properties["item"]
        image = self.shadow_text(obj.name_trans, bg=(128, 128, 128))
        yield MenuItem(image, obj.name_trans, obj.description_trans, obj)


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def initialize_items(self):
    """Get all player inventory items and add them to menu

    :return:
    """
    for name, properties in self.game.player1.inventory.items():
        obj = properties["item"]
        image = self.shadow_text(obj.name, bg=(128, 128, 128))
        yield MenuItem(image, obj.name, obj.description, obj)
# Buggy code
def calc_bounding_rect(self):
    """A rect object that contains all sprites of this group"""
    rect = super(RelativeGroup, self).calc_bounding_rect()
    for sprite in self.sprites():
        print(sprite, sprite.rect)
    # return self.calc_absolute_rect(rect)
    return rect


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def calc_bounding_rect(self):
    """A rect object that contains all sprites of this group"""
    rect = super(RelativeGroup, self).calc_bounding_rect()
    # return self.calc_absolute_rect(rect)
    return rect
# Buggy code
def choose_technique():
    # open menu to choose technique
    menu = self.game.push_state("Menu")
    menu.shrink_to_items = True

    # add techniques to the menu
    for tech in self.monster.moves:
        image = self.shadow_text(tech.name)
        item = MenuItem(image, tech.name, None, tech)
        menu.add(item)

    # position the new menu
    menu.anchor("bottom", self.rect.top)
    menu.anchor("right", self.game.screen.get_rect().right)

    # set next menu after after selection is made
    menu.on_menu_selection = choose_target


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def choose_technique():
    # open menu to choose technique
    menu = self.game.push_state("Menu")
    menu.shrink_to_items = True

    # add techniques to the menu
    for tech in self.monster.moves:
        image = self.shadow_text(tech.name_trans)
        item = MenuItem(image, None, None, tech)
        menu.add(item)

    # position the new menu
    menu.anchor("bottom", self.rect.top)
    menu.anchor("right", self.game.screen.get_rect().right)

    # set next menu after after selection is made
    menu.on_menu_selection = choose_target
# Buggy code
def on_menu_selection(self, menu_item):
    """Called when player has selected something from the inventory

    Currently, opens a new menu depending on the state context

    :param menu_item:
    :return:
    """
    item = menu_item.game_object
    state = self.determine_state_called_from()

    if state in item.usable_in:
        self.open_confirm_use_menu(item)
    else:
        msg = trans("item_cannot_use_here", {"name": item.name})
        tools.open_dialog(self.game, [msg])


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def on_menu_selection(self, menu_item):
    """Called when player has selected something from the inventory

    Currently, opens a new menu depending on the state context

    :param menu_item:
    :return:
    """
    item = menu_item.game_object
    state = self.determine_state_called_from()

    if state in item.usable_in:
        self.open_confirm_use_menu(item)
    else:
        msg = trans("item_cannot_use_here", {"name": item.name_trans})
        tools.open_dialog(self.game, [msg])
# Buggy code
def initialize_items(self):
    """Get all player inventory items and add them to menu

    :return:
    """
    for name, properties in self.game.player1.inventory.items():
        obj = properties["item"]
        image = self.shadow_text(obj.name, bg=(128, 128, 128))
        yield MenuItem(image, obj.name, obj.description, obj)


# Traceback (KeyError)
Traceback (most recent call last):
File "./tuxemon.py", line 60, in <module>
main()
File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
control.main()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 512, in main
self.main_loop()
File "/tmp/Tuxemon/tuxemon/core/control.py", line 573, in main_loop
self.update(time_delta)
File "/tmp/Tuxemon/tuxemon/core/control.py", line 203, in update
state.update(dt)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 156, in update
self.update_phase()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 328, in update_phase
self.handle_action_queue()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 338, in handle_action_queue
self.check_party_hp()
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 614, in check_party_hp
self.faint_monster(monster)
File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 581, in faint_monster
awarded_exp = monster.total_experience/monster.level/len(self._damage_map[monster])
KeyError: <core.components.monster.Monster object at 0x7fb24236ddd0>

# Fixed code
def initialize_items(self):
    """Get all player inventory items and add them to menu

    :return:
    """
    for name, properties in self.game.player1.inventory.items():
        obj = properties["item"]
        image = self.shadow_text(obj.name_trans, bg=(128, 128, 128))
        yield MenuItem(image, obj.name_trans, obj.description_trans, obj)