Skip to content

Conversation

@gaaclarke
Copy link
Member

This passes mypy and pylint. I looked into introducing mypy into ci, but it didn't make sense considering the small number of python scripts.

Test exempt: this is a test

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions bot added the engine flutter/engine related. See also e: labels. label Jan 6, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request focuses on improving the run_tests.py script by adding type annotations and removing lints. The changes significantly enhance code clarity and maintainability by introducing type hints to function signatures and replacing old-style string formatting with f-strings. Additionally, file handling is improved by using context managers and specifying encoding. I've identified a couple of areas for further improvement: one related to a redundant call and another to improve exception handling.


try:
run_cmd([adb_path, 'shell', remote_tests_path])
except:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using a bare except: is generally discouraged as it catches all exceptions, including system-exiting ones like SystemExit or KeyboardInterrupt, making it harder to interrupt the program. It's better to catch a more specific exception. Since the intention here is to catch any error from run_cmd and then re-raise it, except Exception: would be more appropriate.

Suggested change
except:
except Exception:
References
  1. The Google Python Style Guide advises against using bare except: clauses. It recommends catching more specific exceptions or Exception. (link)

logger.info(line.rstrip())

process.wait()
process.wait()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The with subprocess.Popen(...) as process: statement ensures that process.wait() is called when the with block is exited. This explicit call to process.wait() is redundant and can be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion makes sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant now that we can't use popen with with statements

@gaaclarke gaaclarke requested review from b-luk and walley892 January 6, 2026 20:26
Copy link
Contributor

@b-luk b-luk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with the caveat that I haven't written any Python code for many years (and never Python3 or Python with type annotations). So if you want someone with actual Python experience to review it, make sure to include another reviewer.

message.append(f'ninja -C {ios_out_dir} ios_test_flutter')
final_message = (
f"{ios_out_dir} or {ios_test_lib} doesn't exist. "
f'Please run the following commands: \n{chr(10).join(message)}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is chr(10).join() preferred over "\n".join()?

Copy link
Contributor

@b-luk b-luk Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just get rid of this whole message-list/final_message/'\n'-join thing and have one single message f-string. I'm not seeing why this was made to be this slightly convoluted message/final_message/join thing thing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol no, gemini did it automatically and I missed it. thanks. i'll fix it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it looks like f-strings doesn't handle having string literals in the {} expressions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it looks like f-strings doesn't handle having string literals in the {} expressions.

That's surprising. We do have {" ".join(flags)}'] and {",".join(all_types)} in f-strings elsewhere in this file.

Copy link
Member Author

@gaaclarke gaaclarke Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it may be some weird thing with the fact there are 2 fstrings back to back? The linter will complain about the previous line actually: testing/run_tests.py:717:7: E0001: f-string expression part cannot include a backslash (<unknown>, line 717) (syntax-error)

Looked at it a bit more, I'm actually not sure why it freaks out here.

logger.info(line.rstrip())

process.wait()
process.wait()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion makes sense to me.

Comment on lines 718 to +720
# TODO ricardoamador: remove this check when python 2 is deprecated.
version_output = version_output if isinstance(version_output,
str) else version_output.decode(ENCODING)
version_output = version_output.strip()
match = re.match(r'Xcode (\d+)', version_output)
version_output_str = version_output if isinstance(version_output,
str) else version_output.decode(ENCODING)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Python2 still used with this? I think subprocess.Popen with a with block isn't supported in Python2, so maybe this file is supposed to be Python3-only.

If this is only for Python3, I think the TODO is suggesting to simplify this to always do .decode(ENCODING).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It looks like it was introduced in 3.2. We must be using that on ci. We use the 2.7 version of pylint, I would have expected it to flag this, but doesn't look like it can.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them, based on the fact we are using the 2.7 version of pylint i'll assume we are targeting that.

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 6, 2026
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 6, 2026
@auto-submit
Copy link
Contributor

auto-submit bot commented Jan 6, 2026

autosubmit label was removed for flutter/flutter/180597, because - The status or check suite Linux linux_web_engine_tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

Copy link
Contributor

@walley892 walley892 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gaaclarke gaaclarke added this pull request to the merge queue Jan 7, 2026
Merged via the queue into flutter:master with commit 30799e1 Jan 7, 2026
179 checks passed
@gaaclarke gaaclarke deleted the lint-run-tests branch January 7, 2026 22:06
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 8, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 8, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 8, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 8, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants