-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
attempt to improve sched.scheduler.enterabs
/sched.scheduler.enter
#14273
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
Conversation
stdlib/sched.pyi
Outdated
def enterabs(self, time: float, priority: object, action: Callable[PS, R], *args: PS.args, **kwargs: PS.kwargs) -> Event: ... | ||
def enter(self, delay: float, priority: object, action: Callable[PS, R], *args: PS.args, **kwargs: PS.kwargs) -> Event: ... |
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.
These changes are wrong. I'd like to be able to say something like the following, but (afaik) Python's type system doesn't support it1 :(
def enterabs(self, time: float, priority: object, action: Callable[PS, R], *args: PS.args, **kwargs: PS.kwargs) -> Event: ... | |
def enter(self, delay: float, priority: object, action: Callable[PS, R], *args: PS.args, **kwargs: PS.kwargs) -> Event: ... | |
def enterabs(self, time: float, priority: Any, action: Callable[PS, R], argument: PS.args, kwargs: PS.kwargs) -> Event: ... | |
def enter(self, delay: float, priority: Any, action: Callable[PS, R], argument: PS.args, kwargs: PS.kwargs) -> Event: ... |
Footnotes
-
or at least, type checkers do not support it ↩
sched.scheduler.enterabs
/sched.scheduler.enter
This comment has been minimized.
This comment has been minimized.
stdlib/sched.pyi
Outdated
class _MyCallable(Generic[Unpack[_Args], V, R]): | ||
def __call__(self, args: tuple[Unpack[_Args]], kwargs: Mapping[str, V]) -> R: ... |
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.
my idea here is essentially to reinvent the wheel of Callable
so that we can preserve some info about both positional and keyword argument types. The type system isn't perfect here, since there (afiak) no info to preserve perfect info about positional only args, positional/kw args, and kw-only args other than ParamSpec
, which isn't usable in this context (b/c enter
takes argument
/kwargs
, not *args
/**kwargs
).
I expect that V
will be pretty poor at preserving this info for Callable
s with many different kw arg types, but... maybe this is something?
a4fc670
to
52e4d8b
Compare
This comment has been minimized.
This comment has been minimized.
52e4d8b
to
8583f7a
Compare
Nevermind. I tried this out using Even after fiddling with it a bit, the best I could do was:
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
These changes are wrong and should not be merged. I'm hoping there might be a way to improve the type hints here (because I often get this wrong). Unfortunately, I'm not aware of one :(