You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Zenith: default to use a class instead of top-level functions in Python #6728
Change the dagger init template for Python to use a class instead of just functions. Also update documentation snippets to do the same.
Motivation
In an earlier iteration of Dagger modules, when the concept of objects that contain functions were introduced, the Python SDK kept the convenience of being able to define simple top-level functions, without having to convert into a class. Python allows this by transparently “creating” the object and associate the top-level functions with it, behind the scenes. It provides a nicer experience for simple use cases, where users don’t have to get the name right for the class, since it has to match the module name.
However, you can’t add a description to the main object this way. And over time we’ve added state to object types, and constructors to initialize that state. Using state has become a common pattern, so a user may quite often need to convert the top-level functions into a class.
That takes me back to a few years ago, working with React. You used to be able to create components using either a function or a class. Most people prefer the simplicity of functions, but in React, if you reached a point where you needed to access some lifecycle hooks, you’d need to convert the function into a class. I had to do that a lot myself.
I remember the frustration in the community around this, growing as adoption increased1. I’ve found myself doing this in Python a few times too, and I’ve grown concerned that it’ll add some of the same confusion, frustration or just friction for our users.
For this reason, I think we should default to talk about Python SDK modules using the class, instead of top-level functions, in the documentation and examples. It also makes it more consistent with Go and TypeScript.
Deprecation
I have no plans, nor do I suggest, to deprecate top-level functions at this point. They’ll still be available, just more hidden. We’ll revisit at a later time.
Activity