-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Updates contextlib with ParamSpec #153623
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
base: main
Are you sure you want to change the base?
Updates contextlib with ParamSpec #153623
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/153623
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 3552243 with merge base 4f4ecc5 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
ac1e39a
to
c487ef1
Compare
42ae24d
to
3552243
Compare
"""Allow a context manager to be used as a decorator without parentheses.""" | ||
|
||
def __new__(cls, orig_func=None): | ||
@overload |
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.
Mypy doesn't like me returning a Callable from new here, but I am not sure what is the proper way to make it happy.
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.
I guess this is supposed to only ever return an instance of cls ? :p
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.
Mostly good!
if orig_func is None: | ||
return super().__new__(cls) | ||
return cls()(orig_func) | ||
instance = super().__new__(cls) | ||
return cast(Callable[P, R], instance(orig_func)) # type: ignore[misc] |
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.
this is dead code?
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.
I wish it was... definitely deprecated code though
"""Allow a context manager to be used as a decorator without parentheses.""" | ||
|
||
def __new__(cls, orig_func=None): | ||
@overload |
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.
I guess this is supposed to only ever return an instance of cls ? :p
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
Should improve typing for decorators
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames @Lucaskabela