Skip to content

FIX make sure we can execute code with python -OO #953

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

Merged
merged 2 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/whats_new/v0.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ Version 0.10.0 (ongoing)
Changelog
---------

Bug fixes
.........

- Make sure that :class:`~imblearn.utils._docstring.Substitution` is
working with `python -OO` that replace `__doc__` by `None`.
:pr:`953` bu :user:`Guillaume Lemaitre <glemaitre>`.

Compatibility
.............

Expand Down
3 changes: 2 additions & 1 deletion imblearn/utils/_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def __init__(self, *args, **kwargs):
self.params = args or kwargs

def __call__(self, obj):
obj.__doc__ = obj.__doc__.format(**self.params)
if obj.__doc__:
obj.__doc__ = obj.__doc__.format(**self.params)
return obj


Expand Down
14 changes: 14 additions & 0 deletions imblearn/utils/tests/test_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,17 @@ def test_docstring_inject(obj, obj_docstring):
def test_docstring_template():
assert "random_state" in _random_state_docstring
assert "n_jobs" in _n_jobs_docstring


def test_docstring_with_python_OO():
"""Check that we don't raise a warning if the code is executed with -OO.

Non-regression test for:
https://github.com/scikit-learn-contrib/imbalanced-learn/issues/945
"""
instance = cls(param_1="xxx", param_2="yyy")
instance.__doc__ = None # simulate -OO

instance = Substitution(param_1="xxx", param_2="yyy")(instance)

assert instance.__doc__ is None