Skip to content

Commit 758b0e5

Browse files
committed
SklLearner: Correctly restore self.__dict__ for subsequent repr to work
Fixes #2275 patch.object() obviously didn't restore params as expected.
1 parent 9a2b237 commit 758b0e5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Orange/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __repr__(self):
2929
class _ReprableWithParams(Reprable):
3030
def __repr__(self):
3131
# In addition to saving values onto self, SklLearners save into params
32-
with patch.object(self, '__dict__', dict(self.__dict__, **self.params)):
32+
with patch.dict(self.__dict__, self.params):
3333
return super().__repr__()
3434

3535

Orange/tests/test_util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def test_reprable(self):
3737
from Orange.data import ContinuousVariable
3838
from Orange.preprocess.impute import ReplaceUnknownsRandom
3939
from Orange.statistics.distribution import Continuous
40+
from Orange.classification import LogisticRegressionLearner
4041

4142
var = ContinuousVariable('x')
4243
transform = ReplaceUnknownsRandom(var, Continuous(1, var))
@@ -46,6 +47,11 @@ def test_reprable(self):
4647
"variable=ContinuousVariable(name='x', number_of_decimals=3), "
4748
"distribution=Continuous([[ 0.], [ 0.]]))")
4849

50+
# GH 2275
51+
logit = LogisticRegressionLearner()
52+
for _ in range(2):
53+
self.assertEqual(repr(logit), 'LogisticRegressionLearner()')
54+
4955
def test_deepgetattr(self):
5056
class a:
5157
l = []

0 commit comments

Comments
 (0)