Repository navigation
Remove Python 2 / pre-3.7 era idioms - #1047
Merged
Merged
Conversation
ko1in1u
approved these changes
Oct 6, 2026
Mobly requires Python >= 3.11, so a number of compatibility idioms from the
Python 2 and early Python 3 days are now pure noise. This change removes
them without altering behavior:
* `io.open(...)` -> `open(...)` (identical since Python 3.0), and drops the
now-unused `import io` (config_parser, records, utils, iperf_server).
* `from builtins import str` (the `future` package shim) in config_parser.
* `str(bytes, 'utf-8')` -> `bytes.decode('utf-8')` (android_device, adb,
snippet_client_v2).
* `collections.OrderedDict()` -> `{}` where only insertion order is relied on
(guaranteed since 3.7): base_test, suite_runner, controller_manager,
service_manager, records. `TestResultRecord.extra_errors` is now a plain
dict; its `popitem(last=False)` use is replaced with `next(iter(...))`.
Also removes the "OrderedDict#items does not return a sequence in
Python 3.4" comments and the `list(...)` copies they justified.
* `utils.create_dir`: replace the EEXIST/errno dance with
`os.makedirs(..., exist_ok=True)`; drop the "does not support Python 2"
docstring note.
* `base_instrumentation_test`: replace the one-element-list closure hack
with `nonlocal`.
* `records._set_details`: drop the Python 2 text-vs-bytes special casing;
`str(content)` is correct for all inputs on Python 3.
* `#!/usr/bin/env python3.4` -> `python3`, drop `u''` literal
(tools/snippet_shell.py); drop the `coding: utf-8` cookie (docs/conf.py).
No functional change; the full unit test suite passes unchanged.
…er comment cleanup, fix docstrings
xpconanfan
force-pushed
the
modernize-py2-idioms
branch
from
October 7, 2026 04:48
1c32821 to
fe7fb79
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mobly requires Python >= 3.11; this drops leftover Python 2 / pre-3.7 compatibility idioms. No behavior change.
io.open->open; dropfrom builtins import str.str(b, 'utf-8')->b.decode('utf-8').collections.OrderedDict()->{}(dicts are ordered since 3.7);extra_errorsis now a plain dict.create_dir:os.makedirs(..., exist_ok=True)instead of the errno/EEXIST dance.ExceptionRecord.nonlocalinstead of the one-element-list closure hack.python3.4shebang ->python3; dropu''literal and coding cookie.