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
modules: .py files (or, more correctly, anything that can be imported from)
symbols: anything that exists within a module: classes, functions, variables, imported modules, etc. within a file (that means, anything that can marked import from a module)
'public' v.s. 'protected' v.s. 'private':
public: any module or symbol that is publicly available (appears in API)
protected: anything that is meant for internal usage, and that users should not directly use (prefixed _)
private: anything that is restricted to a module or class that outside users should not even have knowledge of (prefixed __; double underscore)
In the PGM, 'protected' and 'private' are used interchangably, as we don't really have actual symbols marked strictly private with double underscore.
Conventions on definitions
In addition, we have the following conventions:
'public' functionality is considered stable and changes in name or behavior are considered breaking.
we intend to not do any breaking changes without a major version bump
therefore any such change within the same major version is either a bug or a bug fix
we will always communicate such changes
'protected' or 'private' functionality is considered unstable and the behavior and names may change over time.
Using any such functionality is considered danger mode and the user is responsible for migrating and handling bugs that arise from it
any public symbol that lives in a private module (including public submodules of a private module) are considered private from the level of the private module
Note: in Python, nothing is truly private and anything can technically be publicly available if you really want it. However, there is an intentionality argument that says that we can treat protected and private symbols as such. Breaking with the intentionality of the functionality is danger mode.
Conventions on changes
Keep existing public symbols public, always; it's a one-way path
Keep private symbols private
Make new imports private as much as possible (rename if needed)
If you create a new module, either place it in the private _core module and/or make it private at least until it's stable
If you create a new symbol within a module, make it private at least until it's stable
If you have to make new public functionality, make sure to double-check; it's a one-way path
Make sure that the docstring is up-to-date
Make sure that the symbol is present in the API reference in the docs
Conventions in code
To make sure we maintain the intentionality across the code, we do the following tricks in the code base:
# safe importing modulesimportmodule_a# exposes publicly; only do this you know what you're doingimport_module_b# reuse internally# safe importing modules under a different nameimport_module_bas_mod_b# reuse internallyimportmodule_aas_mod_a# reuse internally under a new name# unsafe importing modules; DON'T DO THIS, EVER!!!importmodule_aasmod_a# exposes as a new public symbol; weirdimport_module_basmodule_b# exposes as a new public symbol; very dangerous# unsafe reusing. BEWARE!!! this is a one-way pathfrommodule_aimportfunc_c# exposes a public symbol from another module; usually bad practice# because users may import from multiple filesfrom_module_bimportfunc_d# exposes a function from a private module publicly;# useful when you want to prevent breaking changes now and in the future;# only do this if if you know what you're doing# unsafe reusing with renaming. BEWARE!!! this is a one-way pathfrommodule_aimportfunc_casfunc_e# expose a public symbol from another module under a different name;# why ever do this???from_module_bimportfunc_dasfunc_f# expose a public symbol from a private module;# useful if the name in the private module does not suit this module# unsafe exposing private functionality; DON'T DO THIS, EVER!!!frommodule_aimport_func_gasfunc_g# expose a private symbol from another modulefrom_module_bimport_func_hasfunc_h# expose a public symbol from anot# safe reusing and good practice; rename new private symbols as you see fitfrommodule_aimportfunc_cas_func_g# reuse a public symbol from another module;from_module_bimportfunc_das_func_h# reuse a public symbol from another private module;# safe reusing but usually bad practice (unless in tests), but not harmful; change as you see fitfrommodule_aimport_func_e# reuse a private symbol from another module;from_module_bimport_func_f# reuse a private symbol from another private module;frommodule_aimport_func_eas_func_g# reuse a private symbol from another module;from_module_bimport_func_fas_func_h# reuse a private symbol from another private module;
TODO
Try to find a way to make the module graph less convoluted by changing expositions. Make sure to follow the above conventions.
Feel free to create new private modules and private functions where necessary.
The module graph for the Python wrapper is fairly convoluted (see https://power-grid-model.readthedocs.io/en/stable/advanced_documentation/python-wrapper-design.html). This is a direct consequence of the fact that many
Background
Definitions
We make the following distinctions:
.py
files (or, more correctly, anything that can be importedfrom
)import
from a module)_
)__
; double underscore)In the PGM, 'protected' and 'private' are used interchangably, as we don't really have actual symbols marked strictly private with double underscore.
Conventions on definitions
In addition, we have the following conventions:
Note: in Python, nothing is truly private and anything can technically be publicly available if you really want it. However, there is an intentionality argument that says that we can treat protected and private symbols as such. Breaking with the intentionality of the functionality is danger mode.
Conventions on changes
_core
module and/or make it private at least until it's stableConventions in code
To make sure we maintain the intentionality across the code, we do the following tricks in the code base:
TODO
Try to find a way to make the module graph less convoluted by changing expositions. Make sure to follow the above conventions.
Feel free to create new private modules and private functions where necessary.
Relates to #869 .
The text was updated successfully, but these errors were encountered: