ua-generator icon indicating copy to clipboard operation
ua-generator copied to clipboard

Add Mypy Support and Improve Type Hinting

Open plasenca-d opened this issue 6 months ago • 4 comments

This PR introduces static type checking support using Mypy and enhances the overall type hinting throughout the ua-generator library.

Key Changes:

  • Added py.typed marker file: Includes the py.typed file in the src/ua_generator directory to signal PEP 561 compliance, allowing Mypy to recognize the package for type checking.
  • Introduced Mypy Test: Added a new test file test_typing.py specifically for verifying type hints with Mypy. This includes instructions on how to run the check.
  • Enhanced Type Annotations:
    • Added type hints to function signatures, return types, and variables across various modules, including utils.py , client_hints.py , options.py , and data modules within data .
    • Utilized types from the typing module like List , Dict , Union , Literal , and Any for better code clarity and correctness.
    • Improved type definitions within the Version class and its subclasses ( ChromiumVersion , AndroidVersion , WindowsVersion ).

These changes improve code maintainability, reduce potential runtime errors, and make the library easier to use correctly by providing clearer type information.

plasenca-d avatar Apr 27 '25 18:04 plasenca-d

Thank you for your contribution. It's great that you brought up mypy.

However, there are some issues we need to resolve.

iamdual avatar Apr 27 '25 23:04 iamdual

I'm gonna update the typings for Python 3.9 and 3.10

plasenca-d avatar Apr 28 '25 15:04 plasenca-d

@iamdual I already made the changes

plasenca-d avatar Apr 29 '25 01:04 plasenca-d

Hi @plasenca-d, I won't be able to merge until all the missing parts are completed. I can add mypy support for you real quick.

iamdual avatar May 18 '25 12:05 iamdual

Merged #28

iamdual avatar May 31 '25 14:05 iamdual