gh-71042: Add platform.android_ver#116674
Conversation
|
Consistent with iOS in #117052, I've removed the |
Co-authored-by: Victor Stinner <vstinner@python.org>
|
Sorry for the late change, but I've also added an Since Android emulators and physical devices use the same ABI, I didn't originally think there was any need for this flag. But I've now found two cases where small-scale timing issues prevent some emulators from running a test reliably:
|
|
@vstinner: Are you able to merge this? |
vstinner
left a comment
There was a problem hiding this comment.
The change mostly LGTM, but here is another round of review.
|
|
||
| * ``release`` - Android version, as a string (e.g. ``"14"``) | ||
|
|
||
| * ``api_level`` - API level, as an integer (e.g. ``34``) |
There was a problem hiding this comment.
Would you mind to repeat here the difference with https://docs.python.org/dev/library/sys.html#sys.getandroidapilevel and so add a reference to the sys function?
| # a missing one. | ||
| return default | ||
| else: | ||
| return buffer.value.decode("UTF-8", "backslashreplace") |
There was a problem hiding this comment.
Did you consider "surrogateescape" to not lose information? The caller can then decide how to handle surrogate characters. Did you see strings which cannot be decoded from UTF-8 in practice?
There was a problem hiding this comment.
I haven't seen such strings, but this function is likely to be used when building error reports, so perfect round-tripping is less important than making sure it doesn't cause any errors itself.
For that reason, I'd prefer not to use surrogateescape, because surrogates can't be turned back into bytes unless the encode call uses surrogateescape as well, which is something we have no control over, and something the programmer is very unlikely to test.
| if sys.platform == 'android': | ||
| call_func(info_add, 'platform.android_ver', platform, 'android_ver') |
There was a problem hiding this comment.
FYI you can just call:
| if sys.platform == 'android': | |
| call_func(info_add, 'platform.android_ver', platform, 'android_ver') | |
| call_func(info_add, 'platform.android_ver', platform, 'android_ver') |
It does nothing if the function doesn't exist.
There was a problem hiding this comment.
Like the other platform.*_ver functions, android_ver does exist on all platforms, but returns empty values when not running on Android. There's no point in cluttering the report in that case.
Co-authored-by: Victor Stinner <vstinner@python.org>
…getandroidapilevel()
|
Merged, thanks. Welcome Android :-) |
This PR implements the
platform.android_verfunction specified in PEP 738.It also uses the new function to do the following:
platform.systemandplatform.releaseas specified in the PEP📚 Documentation preview 📚: https://cpython-previews--116674.org.readthedocs.build/