Repository: Lightning-Universe/lightning-flash

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.



Discussion:
The KeyError message returns the entire registry and hence it seemed like "print()" function returns the entire registry if an illegal key is sent.

Resolving patch:
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 @@ def get(
         """
         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()]


Test patch:
diff --git a/tests/core/test_registry.py b/tests/core/test_registry.py
--- a/tests/core/test_registry.py
+++ b/tests/core/test_registry.py
@@ -28,19 +28,19 @@ def my_model(nc_input=5, nc_output=6):
         return nn.Linear(nc_input, nc_output), nc_input, nc_output
 
     with pytest.raises(MisconfigurationException, match="You can only register a function, found: Linear"):
-        backbones(nn.Linear(1, 1), name="cho")
+        backbones(nn.Linear(1, 1), name="foo")
 
-    backbones(my_model, name="cho", override=True)
+    backbones(my_model, name="foo", override=True)
 
-    with pytest.raises(MisconfigurationException, match="Function with name: cho and metadata: {}"):
-        backbones(my_model, name="cho", override=False)
+    with pytest.raises(MisconfigurationException, match="Function with name: foo and metadata: {}"):
+        backbones(my_model, name="foo", override=False)
 
     with pytest.raises(KeyError, match="Found no matches"):
-        backbones.get("cho", foo="bar")
+        backbones.get("foo", baz="bar")
 
-    backbones.remove("cho")
-    with pytest.raises(KeyError, match="Key: cho is not in FlashRegistry"):
-        backbones.get("cho")
+    backbones.remove("foo")
+    with pytest.raises(KeyError, match="Key: foo is not in FlashRegistry"):
+        backbones.get("foo")
 
     with pytest.raises(TypeError, match="name` must be a str"):
         backbones(name=float)  # noqa
@@ -59,30 +59,30 @@ def my_model(nc_input=5, nc_output=6):
     assert mlp.weight.shape == (7, 5)
 
     # basic get
-    backbones(my_model, name="cho")
-    assert backbones.get("cho")
+    backbones(my_model, name="foo")
+    assert backbones.get("foo")
 
     # test override
-    backbones(my_model, name="cho", override=True)
-    functions = backbones.get("cho", strict=False)
+    backbones(my_model, name="foo", override=True)
+    functions = backbones.get("foo", strict=False)
     assert len(functions) == 1
 
     # test metadata filtering
-    backbones(my_model, name="cho", namespace="timm", type="resnet")
-    backbones(my_model, name="cho", namespace="torchvision", type="resnet")
-    backbones(my_model, name="cho", namespace="timm", type="densenet")
-    backbones(my_model, name="cho", namespace="timm", type="alexnet")
-    function = backbones.get("cho", with_metadata=True, type="resnet", namespace="timm")
-    assert function["name"] == "cho"
+    backbones(my_model, name="foo", namespace="timm", type="resnet")
+    backbones(my_model, name="foo", namespace="torchvision", type="resnet")
+    backbones(my_model, name="foo", namespace="timm", type="densenet")
+    backbones(my_model, name="foo", namespace="timm", type="alexnet")
+    function = backbones.get("foo", with_metadata=True, type="resnet", namespace="timm")
+    assert function["name"] == "foo"
     assert function["metadata"] == {"namespace": "timm", "type": "resnet"}
 
     # test strict=False and with_metadata=False
-    functions = backbones.get("cho", namespace="timm", strict=False)
+    functions = backbones.get("foo", namespace="timm", strict=False)
     assert len(functions) == 3
     assert all(callable(f) for f in functions)
 
     # test available keys
-    assert backbones.available_keys() == ['cho', 'cho', 'cho', 'cho', 'cho', 'my_model']
+    assert backbones.available_keys() == ['foo', 'foo', 'foo', 'foo', 'foo', 'my_model']
 
 
 # todo (tchaton) Debug this test.