Repository: OpenAssetIO/OpenAssetIO (language: python)

Issue:
Add `__repr__` to `EntityReference`
## What

Add `__repr__` support to `EntityReference`

## Why

```
[<openassetio._openassetio.EntityReference object at 0x10e9b69f0>, <openassetio._openassetio.EntityReference object at 0x10e9b69f0>, <openassetio._openassetio.EntityReference
 object at 0x10e9b69f0>]
```

Makes debugging really hard.

## Acceptance Criteria

```
e = EntityReference("aRef")
repr(e)
<openassetio.EntityReference aRef>
```


Discussion / hints:

Fix patch:
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 731f21835..11215ec4d 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -1,6 +1,15 @@
 Release Notes
 =============
 
+v1.0.0-beta.x.x
+---------------
+
+### Improvements
+
+- Added the string representation of an `EntityReference` when `repr`'d
+  in Python.
+  [#1186](https://github.com/OpenAssetIO/OpenAssetIO/issues/1186)
+
 v1.0.0-beta.1.0
 ---------------
 
diff --git a/src/openassetio-python/cmodule/CMakeLists.txt b/src/openassetio-python/cmodule/CMakeLists.txt
index 8b39a247d..f5c09d20d 100644
--- a/src/openassetio-python/cmodule/CMakeLists.txt
+++ b/src/openassetio-python/cmodule/CMakeLists.txt
@@ -68,7 +68,9 @@ target_link_libraries(openassetio-python-module
     # Core C++ library.
     openassetio-core
     # pybind, including its handy transitive Python-specific properties.
-    pybind11::module pybind11::windows_extras)
+    pybind11::module pybind11::windows_extras
+    $<BUILD_INTERFACE:fmt::fmt-header-only>
+)
 
 target_include_directories(openassetio-python-module
     PRIVATE
diff --git a/src/openassetio-python/cmodule/src/EntityReferenceBinding.cpp b/src/openassetio-python/cmodule/src/EntityReferenceBinding.cpp
index 33ab45713..07442961d 100644
--- a/src/openassetio-python/cmodule/src/EntityReferenceBinding.cpp
+++ b/src/openassetio-python/cmodule/src/EntityReferenceBinding.cpp
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: Apache-2.0
 // Copyright 2013-2022 The Foundry Visionmongers Ltd
+#include <fmt/format.h>
 #include <pybind11/operators.h>
 #include <pybind11/pybind11.h>
 
@@ -7,12 +8,16 @@
 
 #include "_openassetio.hpp"
 
-void registerEntityReference(const py::module &mod) {
+void registerEntityReference(const py::module& mod) {
   using openassetio::EntityReference;
 
   py::class_<EntityReference>{mod, "EntityReference", py::is_final()}
       .def(py::init<openassetio::Str>(), py::arg("entityReferenceString"))
       .def("toString", &EntityReference::toString)
       .def("__str__", &EntityReference::toString)
+      .def("__repr__",
+           [](const EntityReference& self) {
+             return fmt::format("<openassetio.EntityReference {}>", self.toString());
+           })
       .def(py::self == py::self);  // NOLINT(misc-redundant-expression)
 }


Test patch:
diff --git a/src/openassetio-python/tests/package/test_entityreference.py b/src/openassetio-python/tests/package/test_entityreference.py
index a842aea62..3c275322a 100644
--- a/src/openassetio-python/tests/package/test_entityreference.py
+++ b/src/openassetio-python/tests/package/test_entityreference.py
@@ -41,6 +41,14 @@ def test_returns_constructor_supplied_string(self):
         assert an_entity_reference.toString() == expected
 
 
+class Test_EntityReferenve_repr:
+    def test_returns_angle_bracket_string_with_class_and_value(self):
+        for ref_str in ("a://ref", "a 🦆 v1"):
+            expected = f"<openassetio.EntityReference {ref_str}>"
+            a_ref = EntityReference(ref_str)
+            assert repr(a_ref) == expected
+
+
 class Test_EntityReference_equality:
     def test_when_same_then_compares_equal(self):
         assert EntityReference("something") == EntityReference("something")