Skip to content

Commit 842970a

Browse files
authored
FIX make sure we can execute code with python -OO (#953)
1 parent c68211d commit 842970a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

doc/whats_new/v0.10.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Version 0.10.0 (ongoing)
66
Changelog
77
---------
88

9+
Bug fixes
10+
.........
11+
12+
- Make sure that :class:`~imblearn.utils._docstring.Substitution` is
13+
working with `python -OO` that replace `__doc__` by `None`.
14+
:pr:`953` bu :user:`Guillaume Lemaitre <glemaitre>`.
15+
916
Compatibility
1017
.............
1118

imblearn/utils/_docstring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def __init__(self, *args, **kwargs):
1919
self.params = args or kwargs
2020

2121
def __call__(self, obj):
22-
obj.__doc__ = obj.__doc__.format(**self.params)
22+
if obj.__doc__:
23+
obj.__doc__ = obj.__doc__.format(**self.params)
2324
return obj
2425

2526

imblearn/utils/tests/test_docstring.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,17 @@ def test_docstring_inject(obj, obj_docstring):
6666
def test_docstring_template():
6767
assert "random_state" in _random_state_docstring
6868
assert "n_jobs" in _n_jobs_docstring
69+
70+
71+
def test_docstring_with_python_OO():
72+
"""Check that we don't raise a warning if the code is executed with -OO.
73+
74+
Non-regression test for:
75+
https://github.com/scikit-learn-contrib/imbalanced-learn/issues/945
76+
"""
77+
instance = cls(param_1="xxx", param_2="yyy")
78+
instance.__doc__ = None # simulate -OO
79+
80+
instance = Substitution(param_1="xxx", param_2="yyy")(instance)
81+
82+
assert instance.__doc__ is None

0 commit comments

Comments
 (0)