Skip to content

[Workflow] make code-format-helper.py mypy-safe (NFC) #69691

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

Merged
merged 2 commits into from
Oct 20, 2023

Conversation

rprichard
Copy link
Contributor

Fix type errors that mypy reports with code-format-helper.py.

Add a few return type annotations and change param: [str] to
param: list[str].

Leave a few required FormatHelper members missing instead of defining a placeholder:

  • FormatHelper.name
  • FormatHelper.friendly_name
  • FormatHelper.format_run: NotImplementedError() instead of pass

Fix type errors that mypy reports with code-format-helper.py.

Add a few return type annotations and change `param: [str]` to
`param: list[str]`.

Leave a few required FormatHelper members missing instead of defining a
placeholder:
 - FormatHelper.name
 - FormatHelper.friendly_name
 - FormatHelper.format_run: NotImplementedError() instead of `pass`
@rprichard rprichard requested a review from tru October 20, 2023 08:25
@rprichard
Copy link
Contributor Author

Previously mypy was complaining on this file:

$ mypy code-format-helper.py 
code-format-helper.py:29: error: Bracketed expression "[...]" is not valid as a type  [valid-type]
code-format-helper.py:29: note: Did you mean "List[...]"?
code-format-helper.py:36: error: "FormatHelper" has no attribute "friendly_name"  [attr-defined]
code-format-helper.py:44: error: "FormatHelper" has no attribute "instructions"  [attr-defined]
code-format-helper.py:90: error: "FormatHelper" has no attribute "friendly_name"  [attr-defined]
code-format-helper.py:94: error: Bracketed expression "[...]" is not valid as a type  [valid-type]
code-format-helper.py:94: note: Did you mean "List[...]"?
code-format-helper.py:123: error: Bracketed expression "[...]" is not valid as a type  [valid-type]
code-format-helper.py:123: note: Did you mean "List[...]"?
code-format-helper.py:132: error: Bracketed expression "[...]" is not valid as a type  [valid-type]
code-format-helper.py:132: note: Did you mean "List[...]"?
code-format-helper.py:135: error: Return value expected  [return-value]
code-format-helper.py:162: error: Bracketed expression "[...]" is not valid as a type  [valid-type]
code-format-helper.py:162: note: Did you mean "List[...]"?
code-format-helper.py:171: error: Bracketed expression "[...]" is not valid as a type  [valid-type]
code-format-helper.py:171: note: Did you mean "List[...]"?
code-format-helper.py:174: error: Return value expected  [return-value]
Found 11 errors in 1 file (checked 1 source file)

Copy link
Collaborator

@tru tru left a comment

Choose a reason for hiding this comment

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

LGTM

@rprichard
Copy link
Contributor Author

I noticed that I forgot an annotation on DarkerFormatHelper.instructions. I added another commit to fix that. This file now passes mypy --strict code-format-helper.py, which does complain about functions that lack a return type annotation.

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

Successfully merging this pull request may close these issues.

2 participants