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

chore: Refactor type hinting in BaseBackend and its subclasses #107

Merged

Conversation

robberwick
Copy link
Collaborator

  • Use TypeVar and Generic to define a generic type T in BaseBackend.
  • Apply the generic type T to methods and attributes in BaseBackend.
  • Update Win32Backend and UnixLikeBackend to specify the type for T.
  • Reduce repetition of type hinting in constructors and method return types.

This pull request includes several changes to the blinkstick backends to improve type annotations and ensure type consistency across different backends. The most important changes include introducing generics to the BaseBackend class, updating method return types, and adding type ignores for certain imports.

Improvements to type annotations and consistency:

  • src/blinkstick/backends/base.py: Introduced generics to the BaseBackend class and updated method return types to use the new generic type T. [1] [2]
  • src/blinkstick/backends/unix_like.py: Updated the UnixLikeBackend class to use the usb.core.Device type for the generic parameter T and updated method return types accordingly. [1] [2] [3]
  • src/blinkstick/backends/win32.py: Updated the Win32Backend class to use the hid.HidDevice type for the generic parameter T, added type annotations for class attributes, and updated method return types accordingly. [1] [2] [3]
  • src/blinkstick/backends/unix_like.py and src/blinkstick/backends/win32.py: Added # type: ignore comments to suppress type checking for usb and pywinusb imports. [1] [2]
  • src/blinkstick/blinkstick.py: Improved the find_all method to handle cases where no devices are found by using a more concise and type-safe approach.

- Use `TypeVar` and `Generic` to define a generic type `T` in `BaseBackend`.
- Apply the generic type `T` to methods and attributes in `BaseBackend`.
- Update `Win32Backend` and `UnixLikeBackend` to specify the type for `T`.
- Reduce repetition of type hinting in constructors and method return types.
@robberwick robberwick merged commit 3a47472 into arvydas:release/2.0-dev Nov 17, 2024
16 checks passed
@robberwick robberwick deleted the usb-device-type-hinting branch November 17, 2024 11:50
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.

1 participant