prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Adding Non Unique Names To ClassMap Must Be Illegal
  Currently, `add_name` doesn't check if the added `name` is a duplicate or not. This should be illegal, as classes must be unique
  
  https://github.com/airctic/icevision/blob/82f3c7322d5adbc41d6a1b7b9e4327eb32ad23c4/icevision/core/class_map.py#L47-L51
  
  </issue>
  <code>
  [start of icevision/core/class_map.py]
  1 __all__ = ["ClassMap", "BACKGROUND"]
  2 
  3 from icevision.imports import *
  4 
  5 BACKGROUND = "background"
  6 
  7 
  8 class ClassMap:
  9     """Utility class for mapping between class name and id."""
  10 
  11     def __init__(
  12         self,
  13         classes: Optional[Sequence[str]] = None,
  14         background: Optional[str] = BACKGROUND,
  15     ):
  16         self._lock = True
  17 
  18         self._id2class = copy(list(classes)) if classes else []
  19         # insert background if required
  20         self._background = background
  21         if self._background is not None:
  22             try:
  23                 self._id2class.remove(self._background)
  24             except ValueError:
  25                 pass
  26             # background is always index zero
  27             self._id2class.insert(0, self._background)
  28 
  29         self._class2id = {name: i for i, name in enumerate(self._id2class)}
  30 
  31     @property
  32     def num_classes(self):
  33         return len(self)
  34 
  35     def get_by_id(self, id: int) -> str:
  36         return self._id2class[id]
  37 
  38     def get_by_name(self, name: str) -> int:
  39         try:
  40             return self._class2id[name]
  41         except KeyError as e:
  42             if not self._lock:
  43                 return self.add_name(name)
  44             else:
  45                 raise e
  46 
  47     def add_name(self, name) -> int:
  48         self._id2class.append(name)
  49         id = len(self._class2id)
  50         self._class2id[name] = id
  51         return id
  52 
  53     def lock(self):
  54         self._lock = True
  55         return self
  56 
  57     def unlock(self):
  58         self._lock = False
  59         return self
  60 
  61     def __eq__(self, other) -> bool:
  62         if isinstance(other, ClassMap):
  63             return self.__dict__ == other.__dict__
  64         return False
  65 
  66     def __len__(self):
  67         return len(self._id2class)
  68 
  69     def __repr__(self):
  70         return f"<ClassMap: {self._class2id.__repr__()}>"
  71
  [end of icevision/core/class_map.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/icevision/core/class_map.py b/icevision/core/class_map.py
  --- a/icevision/core/class_map.py
  +++ b/icevision/core/class_map.py
  @@ -44,7 +44,13 @@
               else:
                   raise e
   
  -    def add_name(self, name) -> int:
  +    def add_name(self, name: str) -> int:
  +        # Raise error if trying to add duplicate value
  +        if name in self._id2class:
  +            raise ValueError(
  +                f"'{name}' already exists in the ClassMap. You can only add new labels that are unique"
  +            )
  +
           self._id2class.append(name)
           id = len(self._class2id)
           self._class2id[name] = id
  
verification_info: {"golden_diff": "diff --git a/icevision/core/class_map.py b/icevision/core/class_map.py\n--- a/icevision/core/class_map.py\n+++ b/icevision/core/class_map.py\n@@ -44,7 +44,13 @@\n             else:\n                 raise e\n \n-    def add_name(self, name) -> int:\n+    def add_name(self, name: str) -> int:\n+        # Raise error if trying to add duplicate value\n+        if name in self._id2class:\n+            raise ValueError(\n+                f\"'{name}' already exists in the ClassMap. You can only add new labels that are unique\"\n+            )\n+\n         self._id2class.append(name)\n         id = len(self._class2id)\n         self._class2id[name] = id\n", "issue": "Adding Non Unique Names To ClassMap Must Be Illegal\nCurrently, `add_name` doesn't check if the added `name` is a duplicate or not. This should be illegal, as classes must be unique\r\n\r\nhttps://github.com/airctic/icevision/blob/82f3c7322d5adbc41d6a1b7b9e4327eb32ad23c4/icevision/core/class_map.py#L47-L51\n", "before_files": [{"content": "__all__ = [\"ClassMap\", \"BACKGROUND\"]\n\nfrom icevision.imports import *\n\nBACKGROUND = \"background\"\n\n\nclass ClassMap:\n    \"\"\"Utility class for mapping between class name and id.\"\"\"\n\n    def __init__(\n        self,\n        classes: Optional[Sequence[str]] = None,\n        background: Optional[str] = BACKGROUND,\n    ):\n        self._lock = True\n\n        self._id2class = copy(list(classes)) if classes else []\n        # insert background if required\n        self._background = background\n        if self._background is not None:\n            try:\n                self._id2class.remove(self._background)\n            except ValueError:\n                pass\n            # background is always index zero\n            self._id2class.insert(0, self._background)\n\n        self._class2id = {name: i for i, name in enumerate(self._id2class)}\n\n    @property\n    def num_classes(self):\n        return len(self)\n\n    def get_by_id(self, id: int) -> str:\n        return self._id2class[id]\n\n    def get_by_name(self, name: str) -> int:\n        try:\n            return self._class2id[name]\n        except KeyError as e:\n            if not self._lock:\n                return self.add_name(name)\n            else:\n                raise e\n\n    def add_name(self, name) -> int:\n        self._id2class.append(name)\n        id = len(self._class2id)\n        self._class2id[name] = id\n        return id\n\n    def lock(self):\n        self._lock = True\n        return self\n\n    def unlock(self):\n        self._lock = False\n        return self\n\n    def __eq__(self, other) -> bool:\n        if isinstance(other, ClassMap):\n            return self.__dict__ == other.__dict__\n        return False\n\n    def __len__(self):\n        return len(self._id2class)\n\n    def __repr__(self):\n        return f\"<ClassMap: {self._class2id.__repr__()}>\"\n", "path": "icevision/core/class_map.py"}]}