Skip to content

Commit 788361a

Browse files
committed
[API-Compat] Updated ForbidKeywordsDecorator
1 parent 809e8c2 commit 788361a

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

python/paddle/utils/decorator_utils.py

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,18 @@ def process(
9292
return args, processed_kwargs
9393

9494

95-
def param_one_alias(alias_mapping):
96-
def decorator(func):
97-
def wrapper(*args, **kwargs):
98-
if not kwargs:
99-
return func(*args, **kwargs)
100-
if ("input" in kwargs) and ("x" not in kwargs):
101-
kwargs["x"] = kwargs.pop("input")
102-
return func(*args, **kwargs)
103-
104-
wrapper.__signature__ = inspect.signature(func)
105-
return wrapper
106-
107-
return decorator
95+
class ForbidKeywordsDecorator(DecoratorBase):
96+
"""A decorator that hints users to use the correct `compat` functions, when erroneous keyword arguments are detected"""
10897

109-
110-
# *size => shape decorator
111-
class SizeArgsDecorator(DecoratorBase):
112-
"""
113-
Usage Example:
114-
115-
paddle.ones(1, dtype=paddle.float32)
116-
paddle.ones(1, 2, 3, dtype=paddle.float32)
117-
paddle.ones([1, 2, 3], dtype=paddle.float32)
118-
paddle.ones(size=[1, 2, 3], dtype=paddle.float32)
119-
120-
paddle.ones([1, 2, 3], paddle.float32)
121-
paddle.ones(shape=[1, 2, 3], dtype=paddle.float32)
122-
"""
98+
def __init__(
99+
self, illegal_keys: list[str], func_name: str, correct_name: str
100+
) -> None:
101+
super().__init__()
102+
self.illegal_keys = (
103+
[illegal_keys] if isinstance(illegal_keys, str) else illegal_keys
104+
)
105+
self.func_name = func_name
106+
self.correct_name = correct_name
123107

124108
def process(
125109
self, args: tuple[Any, ...], kwargs: dict[str, Any]

0 commit comments

Comments
 (0)