Skip to content

Commit e449122

Browse files
committed
fix #420 warn for 'key' param in render function
previously key was a required parameter if it was given. initially we thought that just making it optional would be fine. however, after some thought, this could lead to unexpected behavior when users don't want 'key' to indicate identity - if it were optional the user would not get any warning when this confusion occured. As a result we will warn the user about this until, in a future release we raise an exception.
1 parent 1da941b commit e449122

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/idom/core/component.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import abc
99
import inspect
10+
import warnings
1011
from functools import wraps
1112
from typing import Any, Callable, Dict, Optional, Tuple, Union
1213
from uuid import uuid4
@@ -31,6 +32,11 @@ def component(function: ComponentRenderFunction) -> Callable[..., "Component"]:
3132
inspect.Parameter.KEYWORD_ONLY,
3233
inspect.Parameter.POSITIONAL_OR_KEYWORD,
3334
)
35+
if key_is_kwarg: # pragma: no cover
36+
warnings.warn(
37+
f"Component render function {function} uses reserved parameter 'key' - this "
38+
"will produce an error in a future release"
39+
)
3440

3541
@wraps(function)
3642
def constructor(*args: Any, key: Optional[Any] = None, **kwargs: Any) -> Component:

0 commit comments

Comments
 (0)