Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 306a5fa

Browse filesBrowse files
committed
FIX signature of deprecated classes
1 parent c24c95f commit 306a5fa
Copy full SHA for 306a5fa

File tree

Expand file treeCollapse file tree

2 files changed

+15
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-0
lines changed

‎sklearn/utils/deprecation.py

Copy file name to clipboardExpand all lines: sklearn/utils/deprecation.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import functools
55
import warnings
6+
from inspect import signature
67

78
__all__ = ["deprecated"]
89

@@ -64,17 +65,21 @@ def _decorate_class(self, cls):
6465
msg += "; %s" % self.extra
6566

6667
new = cls.__new__
68+
sig = signature(cls)
6769

6870
def wrapped(cls, *args, **kwargs):
6971
warnings.warn(msg, category=FutureWarning)
7072
if new is object.__new__:
7173
return object.__new__(cls)
74+
7275
return new(cls, *args, **kwargs)
7376

7477
cls.__new__ = wrapped
7578

7679
wrapped.__name__ = "__new__"
7780
wrapped.deprecated_original = new
81+
# Restore the original signature, see PEP 362.
82+
cls.__signature__ = sig
7883

7984
return cls
8085

‎sklearn/utils/tests/test_deprecation.py

Copy file name to clipboardExpand all lines: sklearn/utils/tests/test_deprecation.py
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
import pickle
6+
from inspect import signature
67

78
import pytest
89

@@ -86,3 +87,12 @@ def test_is_deprecated():
8687

8788
def test_pickle():
8889
pickle.loads(pickle.dumps(mock_function))
90+
91+
92+
def test_deprecated_class_signature():
93+
@deprecated()
94+
class MockClass:
95+
def __init__(self, a, b=1, c=2):
96+
pass
97+
98+
assert list(signature(MockClass).parameters.keys()) == ["a", "b", "c"]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.