Skip to content

Enhance type annotations and error handling in Android build script #135556

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

Closed
wants to merge 2 commits into from

Conversation

bionicbeaverlinux2
Copy link

  • Added type hints for function parameters and return types to improve code clarity and type checking.
  • Enhanced error handling in subprocess calls to provide clearer error messages and prevent crashes.
  • Updated the parse_args function to validate paths for site-packages and working directories.
  • Improved the list_devices and find_device functions to handle exceptions and provide informative error messages.
  • Refactored several functions to use more specific types from the typing module for better type safety.

- Added type hints for function parameters and return types to improve code clarity and type checking.
- Enhanced error handling in subprocess calls to provide clearer error messages and prevent crashes.
- Updated the `parse_args` function to validate paths for site-packages and working directories.
- Improved the `list_devices` and `find_device` functions to handle exceptions and provide informative error messages.
- Refactored several functions to use more specific types from the `typing` module for better type safety.
@python-cla-bot
Copy link

python-cla-bot bot commented Jun 16, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jun 16, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Jun 16, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@mhsmith
Copy link
Member

mhsmith commented Jun 16, 2025

I'm not sure why you've closed, this, but here's some feedback anyway:

Added type hints

Unless the hints are actually being checked, I don't think this is worth the noise. And if they're not being checked, they'll inevitably become wrong in the future, which would be worse than having no hints at all.

Enhanced error handling

Some of this is useful, e.g better error messages in android_env. But it's not good to hide stack traces for unknown exceptions, because it makes them impossible to debug:

        except Exception as e:
            sys.exit(f"Failed to determine host from sysconfig files: {e}")

And some of the exception handlers are redundant, e.g. catching SubprocessError when the only possible subclass is CalledProcessError, which is already being caught in main.

Updated the parse_args function to validate paths

This is also redundant, as the paths are already validated in testbed/app/build.gradle.kts. And in the process you removed the use of abspath, which means passing relative paths will probably break.

@bionicbeaverlinux2
Copy link
Author

Right thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants