-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Added type stub for keyboard #8666
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This is also according to docs
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Thanks, left some feedback
stubs/keyboard/keyboard/__init__.pyi
Outdated
|
||
class _KeyboardListener(_GenericListener): | ||
transition_table: dict[ | ||
tuple[Literal["free"], Literal["up"], Literal["modifier"]] |
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 a little excessive. How do we help users by duplicating this whole table at the type level?
stubs/keyboard/keyboard/__init__.pyi
Outdated
# is_pressed cannot check multi-step hotkeys, so not using _ParseableHotkey | ||
|
||
def is_pressed(hotkey: _Key | _ScanCodeList) -> bool: ... | ||
def call_later(fn: Callable[..., None], args: _P = ..., delay: float = ...) -> None: ... |
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 should be expressible with PEP 646's TypeVarTuple, though we can't use that yet because mypy doesn't support it.
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.
Good to know. I hadn't looked into 3.11's variadic generics yet. That's cool. So this would be dependant on python/mypy#12280
stubs/keyboard/keyboard/__init__.pyi
Outdated
def start_recording( | ||
recorded_events_queue: Queue[KeyboardEvent] | None = ..., | ||
) -> tuple[Queue[KeyboardEvent], Callable[[], None]]: ... | ||
def stop_recording() -> list[deque[KeyboardEvent]]: ... |
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 think it's just a list of KeyboardEvents.
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.
You're right, I got confused into thinking it was a list of deque, but it's just converting
@@ -0,0 +1,6 @@ | |||
basestring = str |
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 would remove this, it's clearly not meant as a part of the API.
stubs/keyboard/keyboard/_generic.pyi
Outdated
_Event: TypeAlias = KeyboardEvent | _MouseEvent | ||
|
||
class GenericListener: | ||
lock: Lock |
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.
lock: Lock | |
lock: ClassVar[Lock] |
stubs/keyboard/keyboard/mouse.pyi
Outdated
def double_click(button: _MouseButton = ...) -> None: ... | ||
def right_click() -> None: ... | ||
def wheel(delta: int = ...) -> None: ... | ||
def move(x: int | c_long, y: int | c_long, absolute: bool = ..., duration: float = ...) -> None: ... |
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.
def move(x: int | c_long, y: int | c_long, absolute: bool = ..., duration: float = ...) -> None: ... | |
def move(x: SupportsInt, y: SupportsInt, absolute: bool = ..., duration: float = ...) -> None: ... |
It calls int()
on x and y. Strictly a few more types are allowed:
Line 200 in 8e4b89a
def __new__(cls: type[Self], __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ... |
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.
Didn't know about that one. Thanks!
stubs/keyboard/keyboard/mouse.pyi
Outdated
else: | ||
def get_position() -> tuple[int, int]: ... | ||
|
||
def hook(callback: _Callback) -> _Callback: ... |
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.
Could use a bound TypeVar to signify that the exact same type is returned.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
No description provided.