Skip to content

Commit a9d361a

Browse files
authored
Python: fix: Preserve class type in experimental_class decorator to avoid type inference issues (microsoft#6709)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> Closes microsoft#6707 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> - Introduce `TypeVar` `T` bounded to `type` to ensure the decorator maintains the class type. - Modify the `experimental_class` decorator to use the bounded `TypeVar` for accurate type hinting. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent bb1eb3a commit a9d361a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

python/semantic_kernel/utils/experimental_decorator.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright (c) Microsoft. All rights reserved.
22

33
from collections.abc import Callable
4+
from typing import TypeVar
5+
6+
T = TypeVar("T", bound=type)
47

58

69
def experimental_function(func: Callable) -> Callable:
@@ -16,7 +19,7 @@ def experimental_function(func: Callable) -> Callable:
1619
return func
1720

1821

19-
def experimental_class(cls: type) -> type:
22+
def experimental_class(cls: T) -> T:
2023
"""Decorator to mark a class as experimental."""
2124
if isinstance(cls, type):
2225
if cls.__doc__:

0 commit comments

Comments
 (0)