netcmd: models: Add a repr method to Query for help in the shell
authorRob van der Linde <rob@catalyst.net.nz>
Tue, 27 Feb 2024 01:09:32 +0000 (14:09 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 1 Mar 2024 04:45:36 +0000 (04:45 +0000)
This means in the shell you can just do User.query(samdb) without having to wrap it in list() all the time.

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
python/samba/netcmd/domain/models/query.py

index 3207208d24966fae5755bd8a6c5888b726e21c0d..a3d280f46a1e98b7292a713f22af8d3c1916028d 100644 (file)
@@ -44,6 +44,10 @@ class Query:
         for message in self.result:
             yield self._from_message(message)
 
+    def __repr__(self):
+        """Provide repr method that provides more useful output in the shell."""
+        return f"<Query {list(self)}>"
+
     def _from_message(self, message):
         """Returns the model class to use to construct instances.