-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mark private functionalities with an underscore to separate better from public API #6636
base: main
Are you sure you want to change the base?
Conversation
The AiiDA public API has been defined in the documentation as every import that can be done from a secondary level. This is however not transparent to users and plugin developers as it is hidden in the doc resulting in a lot of misuse of private functionalities. The widespread use of these private functionalities blocks improvements in the code as we are more hesitant in changing functionalities for wrong backwards compatibility. This PR marks clearly the internal functioanlities with an underscore so a misuse only can happen intentionally. This gives us the opportunity to improve the public API as we can implement replacements for functionalities in the private API that are widely used.
I'd say we push on this and at the meanwhile improve the documentation? One thing to keep mind was such change will break some plugins that heavily use unexposed APIs, there may not too much for
Want to hear your inputs @giovannipizzi @sphuber @superstar54 @mbercx |
Thanks for the work. |
I am personally not a fan of this approach as it doesn't really help with the problem. There may be plenty of users that are not at all familiar with the implicit meaning of a file starting with an underscore. Moreover, as @superstar54 already hinted, there will be resources that are deeper than two levels and should still be public. How will it be made clear which of those can be imported? I think the most common approach for libraries is to simply expose everything that is public API directly at the top-level module. So in The only potential problem I see is that with a package as large as If we are going to break things with this change, I think it would be advisable to do it properly in one go and really think hard what should be part of the public API. |
I think it depends, when the very deeply defined functions are used, it means the user is looking in the src code instead of the documentation to do some magics. It usually manifest two things and nudge us to take some operations:
I agree, especially after the discussion during the coding week with @agoscinski and @khsrali, I also read https://benhoyt.com/writings/python-api-design/. One of the take home message there is "Design your library to be used as import lib ... lib.Thing() rather than from lib import LibThing ... LibThing().". For aiida case is using |
@unkcpz take some sleep bro, it's 2:47 am 😅 |
The AiiDA public API has been defined in the documentation as every import that can be done from a secondary level. This is however not transparent to users and plugin developers as it is hidden in the doc resulting in a lot of misuse of private functionalities. The widespread use of these private functionalities blocks improvements in the code as we are more hesitant in changing functionalities for wrong backwards compatibility.
This PR marks clearly the internal functionalities with an underscore so a misuse only can happen intentionally. It only marks the third level of import with an underscore since any subsequent imports are automatically marked as internal. This gives us the opportunity to improve the public API as we can implement replacements for functionalities in the private API that are widely used.
This means the public API example changes to
EDIT: Need to adapt imports in tests, and docs