Skip to content
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

Merged
merged 18 commits into from
Sep 5, 2022
Merged

Added type stub for keyboard #8666

merged 18 commits into from
Sep 5, 2022

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Sep 2, 2022

No description provided.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

3 similar comments
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Avasam added a commit to Avasam/AutoSplit that referenced this pull request Sep 2, 2022
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Member

@JelleZijlstra JelleZijlstra left a 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


class _KeyboardListener(_GenericListener):
transition_table: dict[
tuple[Literal["free"], Literal["up"], Literal["modifier"]]
Copy link
Member

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?

# 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: ...
Copy link
Member

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.

Copy link
Collaborator Author

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

def start_recording(
recorded_events_queue: Queue[KeyboardEvent] | None = ...,
) -> tuple[Queue[KeyboardEvent], Callable[[], None]]: ...
def stop_recording() -> list[deque[KeyboardEvent]]: ...
Copy link
Member

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.

Copy link
Collaborator Author

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
Copy link
Member

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.

_Event: TypeAlias = KeyboardEvent | _MouseEvent

class GenericListener:
lock: Lock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lock: Lock
lock: ClassVar[Lock]

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: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:

def __new__(cls: type[Self], __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ...

Copy link
Collaborator Author

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!

else:
def get_position() -> tuple[int, int]: ...

def hook(callback: _Callback) -> _Callback: ...
Copy link
Member

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.

@Avasam Avasam requested a review from JelleZijlstra September 4, 2022 23:51
@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit 939fc86 into python:master Sep 5, 2022
@Avasam Avasam deleted the keyboard branch September 6, 2022 21:38
Avasam added a commit to Avasam/AutoSplit that referenced this pull request Sep 6, 2022
Avasam added a commit to Avasam/AutoSplit that referenced this pull request Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants