prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Confusing KerError message for flash registry
  ## 🐛 Bug
  
  <!-- A clear and concise description of what the bug is. -->
  
  ### To Reproduce
  
  Steps to reproduce the behavior:
  
  ```
  from flash.image import ImageClassificationData, ImageClassifier
  
  print(ImageClassifier.backbones.get('abcd'))
  ```
  
  #### Code sample
  <!-- Ideally attach a minimal code sample to reproduce the decried issue.
  Minimal means having the shortest code but still preserving the bug. -->
  
  ### Expected behavior
  
  It should throw a keyerror.
  
  ### Environment
  
   - PyTorch Version (e.g., 1.0):
   - OS (e.g., Linux):
   - How you installed PyTorch (`conda`, `pip`, source):
   - Build command you used (if compiling from source):
   - Python version:
   - CUDA/cuDNN version:
   - GPU models and configuration:
   - Any other relevant information:
  
  ### Additional context
  
  Sending in PR.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `flash/core/registry.py`
  Content:
  ```
  1 # Copyright The PyTorch Lightning team.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #     http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 from functools import partial
  15 from types import FunctionType
  16 from typing import Any, Callable, Dict, List, Optional, Union
  17 
  18 from pytorch_lightning.utilities import rank_zero_info
  19 from pytorch_lightning.utilities.exceptions import MisconfigurationException
  20 
  21 _REGISTERED_FUNCTION = Dict[str, Any]
  22 
  23 
  24 class FlashRegistry:
  25     """This class is used to register function or :class:`functools.partial` class to a registry."""
  26 
  27     def __init__(self, name: str, verbose: bool = False) -> None:
  28         self.name = name
  29         self.functions: List[_REGISTERED_FUNCTION] = []
  30         self._verbose = verbose
  31 
  32     def __len__(self) -> int:
  33         return len(self.functions)
  34 
  35     def __contains__(self, key) -> bool:
  36         return any(key == e["name"] for e in self.functions)
  37 
  38     def __repr__(self) -> str:
  39         return f'{self.__class__.__name__}(name={self.name}, functions={self.functions})'
  40 
  41     def get(
  42         self,
  43         key: str,
  44         with_metadata: bool = False,
  45         strict: bool = True,
  46         **metadata,
  47     ) -> Union[Callable, _REGISTERED_FUNCTION, List[_REGISTERED_FUNCTION], List[Callable]]:
  48         """
  49         This function is used to gather matches from the registry:
  50 
  51         Args:
  52             key: Name of the registered function.
  53             with_metadata: Whether to include the associated metadata in the return value.
  54             strict: Whether to return all matches or just one.
  55             metadata: Metadata used to filter against existing registry item's metadata.
  56         """
  57         matches = [e for e in self.functions if key == e["name"]]
  58         if not matches:
  59             raise KeyError(f"Key: {key} is not in {repr(self)}")
  60 
  61         if metadata:
  62             matches = [m for m in matches if metadata.items() <= m["metadata"].items()]
  63             if not matches:
  64                 raise KeyError("Found no matches that fit your metadata criteria. Try removing some metadata")
  65 
  66         matches = [e if with_metadata else e["fn"] for e in matches]
  67         return matches[0] if strict else matches
  68 
  69     def remove(self, key: str) -> None:
  70         self.functions = [f for f in self.functions if f["name"] != key]
  71 
  72     def _register_function(
  73         self,
  74         fn: Callable,
  75         name: Optional[str] = None,
  76         override: bool = False,
  77         metadata: Optional[Dict[str, Any]] = None
  78     ):
  79         if not isinstance(fn, FunctionType) and not isinstance(fn, partial):
  80             raise MisconfigurationException(f"You can only register a function, found: {fn}")
  81 
  82         name = name or fn.__name__
  83 
  84         if self._verbose:
  85             rank_zero_info(f"Registering: {fn.__name__} function with name: {name} and metadata: {metadata}")
  86 
  87         item = {"fn": fn, "name": name, "metadata": metadata or {}}
  88 
  89         matching_index = self._find_matching_index(item)
  90         if override and matching_index is not None:
  91             self.functions[matching_index] = item
  92         else:
  93             if matching_index is not None:
  94                 raise MisconfigurationException(
  95                     f"Function with name: {name} and metadata: {metadata} is already present within {self}."
  96                     " HINT: Use `override=True`."
  97                 )
  98             self.functions.append(item)
  99 
  100     def _find_matching_index(self, item: _REGISTERED_FUNCTION) -> Optional[int]:
  101         for idx, fn in enumerate(self.functions):
  102             if all(fn[k] == item[k] for k in ("fn", "name", "metadata")):
  103                 return idx
  104 
  105     def __call__(
  106         self,
  107         fn: Optional[Callable[..., Any]] = None,
  108         name: Optional[str] = None,
  109         override: bool = False,
  110         **metadata
  111     ) -> Callable:
  112         """
  113         This function is used to register new functions to the registry along their metadata.
  114 
  115         Functions can be filtered using metadata using the ``get`` function.
  116 
  117         """
  118         if fn is not None:
  119             self._register_function(fn=fn, name=name, override=override, metadata=metadata)
  120             return fn
  121 
  122         # raise the error ahead of time
  123         if not (name is None or isinstance(name, str)):
  124             raise TypeError(f'`name` must be a str, found {name}')
  125 
  126         def _register(cls):
  127             self._register_function(fn=cls, name=name, override=override, metadata=metadata)
  128             return cls
  129 
  130         return _register
  131 
  132     def available_keys(self) -> List[str]:
  133         return sorted(v["name"] for v in self.functions)
  134
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/flash/core/registry.py b/flash/core/registry.py
  --- a/flash/core/registry.py
  +++ b/flash/core/registry.py
  @@ -56,7 +56,7 @@
           """
           matches = [e for e in self.functions if key == e["name"]]
           if not matches:
  -            raise KeyError(f"Key: {key} is not in {repr(self)}")
  +            raise KeyError(f"Key: {key} is not in {type(self).__name__}")
   
           if metadata:
               matches = [m for m in matches if metadata.items() <= m["metadata"].items()]
  
verification_info: {"golden_diff": "diff --git a/flash/core/registry.py b/flash/core/registry.py\n--- a/flash/core/registry.py\n+++ b/flash/core/registry.py\n@@ -56,7 +56,7 @@\n         \"\"\"\n         matches = [e for e in self.functions if key == e[\"name\"]]\n         if not matches:\n-            raise KeyError(f\"Key: {key} is not in {repr(self)}\")\n+            raise KeyError(f\"Key: {key} is not in {type(self).__name__}\")\n \n         if metadata:\n             matches = [m for m in matches if metadata.items() <= m[\"metadata\"].items()]\n", "issue": "Confusing KerError message for flash registry\n## \ud83d\udc1b Bug\r\n\r\n<!-- A clear and concise description of what the bug is. -->\r\n\r\n### To Reproduce\r\n\r\nSteps to reproduce the behavior:\r\n\r\n```\r\nfrom flash.image import ImageClassificationData, ImageClassifier\r\n\r\nprint(ImageClassifier.backbones.get('abcd'))\r\n```\r\n\r\n#### Code sample\r\n<!-- Ideally attach a minimal code sample to reproduce the decried issue.\r\nMinimal means having the shortest code but still preserving the bug. -->\r\n\r\n### Expected behavior\r\n\r\nIt should throw a keyerror.\r\n\r\n### Environment\r\n\r\n - PyTorch Version (e.g., 1.0):\r\n - OS (e.g., Linux):\r\n - How you installed PyTorch (`conda`, `pip`, source):\r\n - Build command you used (if compiling from source):\r\n - Python version:\r\n - CUDA/cuDNN version:\r\n - GPU models and configuration:\r\n - Any other relevant information:\r\n\r\n### Additional context\r\n\r\nSending in PR.\r\n\n", "before_files": [{"content": "# Copyright The PyTorch Lightning team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nfrom functools import partial\nfrom types import FunctionType\nfrom typing import Any, Callable, Dict, List, Optional, Union\n\nfrom pytorch_lightning.utilities import rank_zero_info\nfrom pytorch_lightning.utilities.exceptions import MisconfigurationException\n\n_REGISTERED_FUNCTION = Dict[str, Any]\n\n\nclass FlashRegistry:\n    \"\"\"This class is used to register function or :class:`functools.partial` class to a registry.\"\"\"\n\n    def __init__(self, name: str, verbose: bool = False) -> None:\n        self.name = name\n        self.functions: List[_REGISTERED_FUNCTION] = []\n        self._verbose = verbose\n\n    def __len__(self) -> int:\n        return len(self.functions)\n\n    def __contains__(self, key) -> bool:\n        return any(key == e[\"name\"] for e in self.functions)\n\n    def __repr__(self) -> str:\n        return f'{self.__class__.__name__}(name={self.name}, functions={self.functions})'\n\n    def get(\n        self,\n        key: str,\n        with_metadata: bool = False,\n        strict: bool = True,\n        **metadata,\n    ) -> Union[Callable, _REGISTERED_FUNCTION, List[_REGISTERED_FUNCTION], List[Callable]]:\n        \"\"\"\n        This function is used to gather matches from the registry:\n\n        Args:\n            key: Name of the registered function.\n            with_metadata: Whether to include the associated metadata in the return value.\n            strict: Whether to return all matches or just one.\n            metadata: Metadata used to filter against existing registry item's metadata.\n        \"\"\"\n        matches = [e for e in self.functions if key == e[\"name\"]]\n        if not matches:\n            raise KeyError(f\"Key: {key} is not in {repr(self)}\")\n\n        if metadata:\n            matches = [m for m in matches if metadata.items() <= m[\"metadata\"].items()]\n            if not matches:\n                raise KeyError(\"Found no matches that fit your metadata criteria. Try removing some metadata\")\n\n        matches = [e if with_metadata else e[\"fn\"] for e in matches]\n        return matches[0] if strict else matches\n\n    def remove(self, key: str) -> None:\n        self.functions = [f for f in self.functions if f[\"name\"] != key]\n\n    def _register_function(\n        self,\n        fn: Callable,\n        name: Optional[str] = None,\n        override: bool = False,\n        metadata: Optional[Dict[str, Any]] = None\n    ):\n        if not isinstance(fn, FunctionType) and not isinstance(fn, partial):\n            raise MisconfigurationException(f\"You can only register a function, found: {fn}\")\n\n        name = name or fn.__name__\n\n        if self._verbose:\n            rank_zero_info(f\"Registering: {fn.__name__} function with name: {name} and metadata: {metadata}\")\n\n        item = {\"fn\": fn, \"name\": name, \"metadata\": metadata or {}}\n\n        matching_index = self._find_matching_index(item)\n        if override and matching_index is not None:\n            self.functions[matching_index] = item\n        else:\n            if matching_index is not None:\n                raise MisconfigurationException(\n                    f\"Function with name: {name} and metadata: {metadata} is already present within {self}.\"\n                    \" HINT: Use `override=True`.\"\n                )\n            self.functions.append(item)\n\n    def _find_matching_index(self, item: _REGISTERED_FUNCTION) -> Optional[int]:\n        for idx, fn in enumerate(self.functions):\n            if all(fn[k] == item[k] for k in (\"fn\", \"name\", \"metadata\")):\n                return idx\n\n    def __call__(\n        self,\n        fn: Optional[Callable[..., Any]] = None,\n        name: Optional[str] = None,\n        override: bool = False,\n        **metadata\n    ) -> Callable:\n        \"\"\"\n        This function is used to register new functions to the registry along their metadata.\n\n        Functions can be filtered using metadata using the ``get`` function.\n\n        \"\"\"\n        if fn is not None:\n            self._register_function(fn=fn, name=name, override=override, metadata=metadata)\n            return fn\n\n        # raise the error ahead of time\n        if not (name is None or isinstance(name, str)):\n            raise TypeError(f'`name` must be a str, found {name}')\n\n        def _register(cls):\n            self._register_function(fn=cls, name=name, override=override, metadata=metadata)\n            return cls\n\n        return _register\n\n    def available_keys(self) -> List[str]:\n        return sorted(v[\"name\"] for v in self.functions)\n", "path": "flash/core/registry.py"}], "after_files": [{"content": "# Copyright The PyTorch Lightning team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nfrom functools import partial\nfrom types import FunctionType\nfrom typing import Any, Callable, Dict, List, Optional, Union\n\nfrom pytorch_lightning.utilities import rank_zero_info\nfrom pytorch_lightning.utilities.exceptions import MisconfigurationException\n\n_REGISTERED_FUNCTION = Dict[str, Any]\n\n\nclass FlashRegistry:\n    \"\"\"This class is used to register function or :class:`functools.partial` class to a registry.\"\"\"\n\n    def __init__(self, name: str, verbose: bool = False) -> None:\n        self.name = name\n        self.functions: List[_REGISTERED_FUNCTION] = []\n        self._verbose = verbose\n\n    def __len__(self) -> int:\n        return len(self.functions)\n\n    def __contains__(self, key) -> bool:\n        return any(key == e[\"name\"] for e in self.functions)\n\n    def __repr__(self) -> str:\n        return f'{self.__class__.__name__}(name={self.name}, functions={self.functions})'\n\n    def get(\n        self,\n        key: str,\n        with_metadata: bool = False,\n        strict: bool = True,\n        **metadata,\n    ) -> Union[Callable, _REGISTERED_FUNCTION, List[_REGISTERED_FUNCTION], List[Callable]]:\n        \"\"\"\n        This function is used to gather matches from the registry:\n\n        Args:\n            key: Name of the registered function.\n            with_metadata: Whether to include the associated metadata in the return value.\n            strict: Whether to return all matches or just one.\n            metadata: Metadata used to filter against existing registry item's metadata.\n        \"\"\"\n        matches = [e for e in self.functions if key == e[\"name\"]]\n        if not matches:\n            raise KeyError(f\"Key: {key} is not in {type(self).__name__}\")\n\n        if metadata:\n            matches = [m for m in matches if metadata.items() <= m[\"metadata\"].items()]\n            if not matches:\n                raise KeyError(\"Found no matches that fit your metadata criteria. Try removing some metadata\")\n\n        matches = [e if with_metadata else e[\"fn\"] for e in matches]\n        return matches[0] if strict else matches\n\n    def remove(self, key: str) -> None:\n        self.functions = [f for f in self.functions if f[\"name\"] != key]\n\n    def _register_function(\n        self,\n        fn: Callable,\n        name: Optional[str] = None,\n        override: bool = False,\n        metadata: Optional[Dict[str, Any]] = None\n    ):\n        if not isinstance(fn, FunctionType) and not isinstance(fn, partial):\n            raise MisconfigurationException(f\"You can only register a function, found: {fn}\")\n\n        name = name or fn.__name__\n\n        if self._verbose:\n            rank_zero_info(f\"Registering: {fn.__name__} function with name: {name} and metadata: {metadata}\")\n\n        item = {\"fn\": fn, \"name\": name, \"metadata\": metadata or {}}\n\n        matching_index = self._find_matching_index(item)\n        if override and matching_index is not None:\n            self.functions[matching_index] = item\n        else:\n            if matching_index is not None:\n                raise MisconfigurationException(\n                    f\"Function with name: {name} and metadata: {metadata} is already present within {self}.\"\n                    \" HINT: Use `override=True`.\"\n                )\n            self.functions.append(item)\n\n    def _find_matching_index(self, item: _REGISTERED_FUNCTION) -> Optional[int]:\n        for idx, fn in enumerate(self.functions):\n            if all(fn[k] == item[k] for k in (\"fn\", \"name\", \"metadata\")):\n                return idx\n\n    def __call__(\n        self,\n        fn: Optional[Callable[..., Any]] = None,\n        name: Optional[str] = None,\n        override: bool = False,\n        **metadata\n    ) -> Callable:\n        \"\"\"\n        This function is used to register new functions to the registry along their metadata.\n\n        Functions can be filtered using metadata using the ``get`` function.\n\n        \"\"\"\n        if fn is not None:\n            self._register_function(fn=fn, name=name, override=override, metadata=metadata)\n            return fn\n\n        # raise the error ahead of time\n        if not (name is None or isinstance(name, str)):\n            raise TypeError(f'`name` must be a str, found {name}')\n\n        def _register(cls):\n            self._register_function(fn=cls, name=name, override=override, metadata=metadata)\n            return cls\n\n        return _register\n\n    def available_keys(self) -> List[str]:\n        return sorted(v[\"name\"] for v in self.functions)\n", "path": "flash/core/registry.py"}]}