New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add typehint for deprecated and experimental #3575
Conversation
@@ -134,7 +150,7 @@ def wrapped_init(self, *args, **kwargs) -> None: # type: ignore | |||
|
|||
_original_init(self, *args, **kwargs) | |||
|
|||
cls.__init__ = wrapped_init | |||
setattr(cls, "__init__", wrapped_init) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python/mypy#2427 (comment)
(But some linter is not happy with the hack: python/mypy#2427 (comment), I'm not sure whether it is preferred or not)
Codecov Report
@@ Coverage Diff @@
## master #3575 +/- ##
==========================================
+ Coverage 90.96% 90.98% +0.01%
==========================================
Files 160 160
Lines 12287 12309 +22
==========================================
+ Hits 11177 11199 +22
Misses 1110 1110
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
optuna/_deprecated.py:171: error: Argument 1 to "_deprecated_class" has incompatible type "Type[Any]"; expected "CT"
optuna/_deprecated.py:173: error: Argument 1 to "_deprecated_func" has incompatible type "Union[Callable[FP, FT], CT]"; expected "Callable[FP, FT]" optuna/optuna/_experimental.py Line 123 in f98a6de
I think it's difficult to capture TypeVar in the codebase. Because we need to utilize typing feature, I'm thinking of dividing |
File changes is extremely huge since this PR divides |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my late response. I agree to divide the decorators for functions and classes, which clarify the types. I will check the implementation detail later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@himkt Could you resolve a conflict? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late. LGTM except a very minor comment.
I'd like to merge this PR after the conflict is resolved. |
Co-authored-by: Hideaki Imamura <38826298+HideakiImamura@users.noreply.github.com>
…to decorator-typehint
I'm sorry I found the additional docstring error. 616dff2 fixes them. |
Let me merge this PR. Thanks for the great work! |
import warnings | ||
|
||
from packaging import version | ||
from typing_extensions import ParamSpec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this break for older versions of typing_extensions, see https://stackoverflow.com/questions/71944041/using-python-code-typed-with-paramspec-on-older-versions-of-python @himkt
For #3572.
The main idea comes from #3270 (microsoft/pyright#774 (comment) for the original context)
I use
@overload
to enable type inference for both function and class.Motivation
This PR aims to enable type inference for deprecated or experimental APIs.
Description of the changes