-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[python-package] prefix all internal object names with "_" #5313
Comments
Thanks for writing this up, I support it. Are we also adding the |
There is already a LightGBM/python-package/lightgbm/__init__.py Lines 30 to 36 in 1b43214
Are you talking about also adding a I don't know enough about this to know whether or not that would work. Like I'm not sure if |
Yeah I meant at the module level, I believe it would be very useful for Edit: Adding reference
https://docs.python.org/3/reference/simple_stmts.html#import Edit2:
So we can set |
Ok nice! I hadn't thought of that. Totally support that idea. I think that new public classes and functions are rare enough in this project that the communication benefit of doing that is worth the slight additional maintenance burden. |
I'm +1 for
Also I'm proposing rethinking which properties of LightGBM/python-package/lightgbm/basic.py Line 1200 in 1b43214
LightGBM/python-package/lightgbm/basic.py Line 2581 in 1b43214
|
I'm +1 |
I'm +1 for this proposal! Thanks. |
Ok thanks all! I'll update the description and convert this from an RFC to a regular maintenance issue, similar to #3756 . |
I've updated the description and title to describe how to contribute on this initiative. @StrikerRUS @jmoralez feel free to edit it with any changes you'd like! For example, I didn't list out any class attributes yet (but agree with the idea in #5313 (comment)). |
I'm glad we originally opened this as a But I'm going to take this over and finish it. It's been open for 6 months, and I'd like to get these changes in for v4.0.0 (#5153). |
The last piece of this is @StrikerRUS 's proposal to also make some more of the class attributes for public classes private. Here's my proposal for which class attributes I think we should make private in the v4.0.0 release:
@jmoralez @guolinke @StrikerRUS @shiyu1994 @btrotta what do you think? |
This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
Short Description
I'm opening this RFC to propose the following:
The convention "anything starting with
_
is internal" is common in Python programming. If LightGBM's Python package followed that convention consistently, it would simplify LightGBM's position on which parts of the Python package are considered "internal" and subject to breaking changes in any release.Detailed Description
In pursuit of the v4.0.0 release (#5153), we have been accepting breaking changes which simplify the project and reduce its maintenance burden, so that limited maintainer time can be focused on providing a good experience with LightGBM's main functionality.
I think "all internal objects should begin with
_
" is one such type of change. Making it clearer which parts of the Python package are considered internal reduces the surface area of the public API which users need to consider, and increases contributors' flexibility to change implementations without breaking user code.R packages support a "namespace" concept (see "Writing R extensions"), which clearly separates exported and internal objects, and I think that mechanism has been really helpful. The closest thing that Python has, to my knowledge, is the
__all__
member for modules (https://docs.python.org/3/tutorial/modules.html#importing-from-a-package).__all__
controls the behavior of "star imports".For example, if you run the following:
the only LightGBM objects you'll see are those in the package's
__all__
.This mechanism is a good start, but prefixing all internal objects with
_
would be an even stronger signal about which things are internal. It would also improve the consistency of the Python package's code.Specific Proposal
expand to see original proposal (click me)
I am proposing that the following be prefixed with a
_
and treated as internal:LightGBM/python-package/lightgbm/basic.py
Line 128 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 144 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 155 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 160 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 168 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 175 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 190 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 240 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 248 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 256 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 264 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 272 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 277 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 282 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 292 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Lines 436 to 470 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 472 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 482 in ff947bf
LightGBM/python-package/lightgbm/basic.py
Line 502 in ff947bf
LightGBM/python-package/lightgbm/libpath.py
Line 9 in ff947bf
Considerations for Implementation
Check that any name being modified is only used at runtime and not part of the state for objects like
Booster
orLGBMClassifier
which might be pickled (sincepickle
only stores references to imports and expects to be able to reference them when runningload()
).Status: Accepted
@StrikerRUS @jmoralez @shiyu1994 @guolinke Whenever you have time, will you please comment here on whether or not you support this proposal? Thank you for your time and consideration.This was originally opened as a request for comment, but it's been accepted and we're now accepting contributions to make more of the Python package's namespace private?
How to Contribute
Anyone is welcome to submit a pull request to help contribute to this effort.
Please limit pull requests to 1 function/method/module per pull request, to make them easier to review.
When you open pull requests, please put
Contributes to #5313
in the description.Add
__all__
entries to modules.python-package/basic.py
([python-package] make public API members explicit with module-level __all__ variables #5655)python-package/callback.py
([python-package] make public API members explicit with module-level __all__ variables #5655)python-package/dask.py
([python-package] make public API members explicit with module-level __all__ variables #5655)python-package/engine.py
([python-package] make public API members explicit with module-level __all__ variables #5655)python-package/libpath.py
([python-package] make public API members explicit with module-level __all__ variables #5655)python-package/plotting.py
([python-package] make public API members explicit with module-level __all__ variables #5655)python-package/sklearn.py
([python-package] make public API members explicit with module-level __all__ variables #5655)Prefix objects, functions, class attributes with
_
basic.ZERO_THRESHOLD
([python-package] prefix internal objects with '_' #5654)basic.NUMERIC_TYPES
([python-package] prefix NUMERIC_TYPES with _ to make it a internal object #5409)basic.is_numeric()
([python] Prefixbasic.is_numeric()
with _ #5421)basic.is_numpy_1d_array()
([python-package] prefix is_numpy_1d_array with _ #5520)basic.is_numpy_column_array()
([python-package] prefix is_numpy_column_array with _ #5531)basic.cast_numpy_array_to_dtype()
([python-package] prefix cast_numpy_array_to_dtype with _ #5532)basic.is_1d_list()
([python-package] prefix several internal functions with _ #5545)basic.list_to_1d_numpy()
([python-package] prefix several internal functions with _ #5545)basic.cfloat32_array_to_numpy()
([python-package] prefix several internal functions with _ #5545)basic.cfloat64_array_to_numpy()
([python-package] prefix several internal functions with _ #5545)basic.cint32_array_to_numpy()
([python-package] prefix several internal functions with _ #5545)basic.cint64_array_to_numpy()
([python-package] prefix several internal functions with _ #5545)basic.c_str()
([python-package] prefix several internal functions with _ #5545)basic.c_array()
([python-package] prefix several internal functions with _ #5545)basic.json_default_with_numpy()
([python-package] prefix internal objects with '_' #5654)basic.param_dict_to_str()
([python-package] prefix internal objects with '_' #5654)basic.MAX_INT32
([python-package] prefix internal objects with '_' #5654)basic.C_API_DTYPE_FLOAT32
([python-package] prefix internal objects with '_' #5654)basic.C_API_DTYPE_FLOAT64
([python-package] prefix internal objects with '_' #5654)basic.C_API_DTYPE_INT32
([python-package] prefix internal objects with '_' #5654)basic.C_API_DTYPE_INT64
([python-package] prefix internal objects with '_' #5654)basic.C_API_IS_ROW_MAJOR
([python-package] prefix internal objects with '_' #5654)basic.C_API_PREDICT_NORMAL
([python-package] prefix internal objects with '_' #5654)basic.C_API_PREDICT_RAW_SCORE
([python-package] prefix internal objects with '_' #5654)basic.C_API_PREDICT_LEAF_INDEX
([python-package] prefix internal objects with '_' #5654)basic.C_API_PREDICT_CONTRIB
([python-package] prefix internal objects with '_' #5654)basic.C_API_MATRIX_TYPE_CSR
([python-package] prefix internal objects with '_' #5654)basic.C_API_MATRIX_TYPE_CSC
([python-package] prefix internal objects with '_' #5654)basic.C_API_FEATURE_IMPORTANCE_SPLIT
([python-package] prefix internal objects with '_' #5654)basic.C_API_FEATURE_IMPORTANCE_GAIN
([python-package] prefix internal objects with '_' #5654)basic.FIELD_TYPE_MAPPER
([python-package] prefix internal objects with '_' #5654)basic.FEATURE_IMPORTANCE_TYPE_MAPPER
([python-package] prefix internal objects with '_' #5654)basic.convert_from_sliced_object()
([python-package] prefix basic.convert_from_sliced_object with _ #5613)basic.c_float_array()
([python-package] prefix c_int_array and c_float_array with _ #5614)basic.c_int_array()
([python-package] prefix c_int_array and c_float_array with _ #5614)The text was updated successfully, but these errors were encountered: