Top level methods should not return generic objects
Service#confs for example returns a Collection object which is really confusing, just having an empty class called Confs that inherit from Collection would be so much simpler.
I'm not sure I agree. Polluting the namespace with empty objects seems unnecessary and bad practice. Nearly all Splunk collections have the same behavior, so no reason to give each one a different name. But, I'm willing to be swayed with a great argument :)
Well, then it's really unclear on what a method returns and it will be hard to create a good documentation.
It's easy to doc that Service#confs returns a collection item but much harder to doc how to get a specific conf file.
I my opinion I would skip the lambda functions (which we had a hard time figuring out what they do) and just implement those lambda functions a member functions:
class Confs(Collection):
# From Collection
def _item(self, service, conf):
return Conf(...)
There are two separate issues here.
-
A request to create, in effect, "nominal" types to reflect the various distinct entity & collection types
-
A request to parameterize the collection implementations using subclass overrides instead of the current method of passing optional lambdas to the "base" class constructor.
Both requests would be completely natural in an object oriented language, but Python is "structurally" typed (duck typed, if you prefer) and in my opinion we are better off with a more functional style of usage, which has been our general approach in this SDK.
Regarding the specific asks:
-
Python is not a nominally typed language and I think it would be a mistake to create empty types to play the role of a named placeholder.
-
I think the current implementation has the advantage of being more compact and reducing the proliferation of types and I am not convinced that it is surprising when considered from the point of view of a dynamic language with higher order functions.