Skip to content

Commit e53c208

Browse files
Rotzbuaper1234
authored andcommitted
feat(typing): add if possible
1 parent edbfb79 commit e53c208

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

Diff for: reportsizedeltas/reportsizedeltas.py

+34-34
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
logger = logging.getLogger(__name__)
1818

1919

20-
def main():
20+
def main() -> None:
2121
set_verbosity(enable_verbosity=False)
2222

2323
if "INPUT_SIZE-DELTAS-REPORTS-ARTIFACT-NAME" in os.environ:
@@ -32,7 +32,7 @@ def main():
3232
report_size_deltas.report_size_deltas()
3333

3434

35-
def set_verbosity(enable_verbosity):
35+
def set_verbosity(enable_verbosity: bool) -> None:
3636
"""Turn debug output on or off.
3737
3838
Keyword arguments:
@@ -52,7 +52,7 @@ def set_verbosity(enable_verbosity):
5252

5353

5454
class ReportSizeDeltas:
55-
"""Methods for creating and submitting the memory usage change reports
55+
"""Methods for creating and submitting the memory usage change reports.
5656
5757
Keyword arguments:
5858
repository_name -- repository owner and name e.g., octocat/Hello-World
@@ -63,7 +63,7 @@ class ReportSizeDeltas:
6363
not_applicable_indicator = "N/A"
6464

6565
class ReportKeys:
66-
"""Key names used in the sketches report dictionary"""
66+
"""Key names used in the sketches report dictionary."""
6767
boards = "boards"
6868
board = "board"
6969
commit_hash = "commit_hash"
@@ -80,12 +80,12 @@ class ReportKeys:
8080
sketches = "sketches"
8181
compilation_success = "compilation_success"
8282

83-
def __init__(self, repository_name, sketches_reports_source, token):
83+
def __init__(self, repository_name: str, sketches_reports_source: str, token: str) -> None:
8484
self.repository_name = repository_name
8585
self.sketches_reports_source = sketches_reports_source
8686
self.token = token
8787

88-
def report_size_deltas(self):
88+
def report_size_deltas(self) -> None:
8989
"""Comment a report of memory usage change to pull request(s)."""
9090
if os.environ["GITHUB_EVENT_NAME"] == "pull_request":
9191
# The sketches reports will be in a local folder location specified by the user
@@ -95,7 +95,7 @@ def report_size_deltas(self):
9595
# Scan the repository's pull requests and comment memory usage change reports where appropriate.
9696
self.report_size_deltas_from_workflow_artifacts()
9797

98-
def report_size_deltas_from_local_reports(self):
98+
def report_size_deltas_from_local_reports(self) -> None:
9999
"""Comment a report of memory usage change to the pull request."""
100100
sketches_reports_folder = pathlib.Path(os.environ["GITHUB_WORKSPACE"], self.sketches_reports_source)
101101
sketches_reports = self.get_sketches_reports(artifact_folder_object=sketches_reports_folder)
@@ -108,7 +108,7 @@ def report_size_deltas_from_local_reports(self):
108108

109109
self.comment_report(pr_number=pr_number, report_markdown=report)
110110

111-
def report_size_deltas_from_workflow_artifacts(self):
111+
def report_size_deltas_from_workflow_artifacts(self) -> None:
112112
"""Scan the repository's pull requests and comment memory usage change reports where appropriate."""
113113
# Get the repository's pull requests
114114
logger.debug("Getting PRs for " + self.repository_name)
@@ -164,8 +164,8 @@ def report_size_deltas_from_workflow_artifacts(self):
164164
page_number += 1
165165
page_count = api_data["page_count"]
166166

167-
def report_exists(self, pr_number, pr_head_sha):
168-
"""Return whether a report has already been commented to the pull request thread for the latest workflow run
167+
def report_exists(self, pr_number: int, pr_head_sha: str) -> bool:
168+
"""Return whether a report has already been commented to the pull request thread for the latest workflow run.
169169
170170
Keyword arguments:
171171
pr_number -- number of the pull request to check
@@ -191,8 +191,8 @@ def report_exists(self, pr_number, pr_head_sha):
191191
# No reports found for the PR's head SHA
192192
return False
193193

194-
def get_artifact_download_url_for_sha(self, pr_user_login, pr_head_ref, pr_head_sha):
195-
"""Return the report artifact download URL associated with the given head commit hash
194+
def get_artifact_download_url_for_sha(self, pr_user_login: str, pr_head_ref: str, pr_head_sha: str) -> str | None:
195+
"""Return the report artifact download URL associated with the given head commit hash.
196196
197197
Keyword arguments:
198198
pr_user_login -- user name of the PR author (used to reduce number of GitHub API requests)
@@ -223,8 +223,8 @@ def get_artifact_download_url_for_sha(self, pr_user_login, pr_head_ref, pr_head_
223223
# No matching artifact found
224224
return None
225225

226-
def get_artifact_download_url_for_run(self, run_id):
227-
"""Return the report artifact download URL associated with the given GitHub Actions workflow run
226+
def get_artifact_download_url_for_run(self, run_id: str) -> str | None:
227+
"""Return the report artifact download URL associated with the given GitHub Actions workflow run.
228228
229229
Keyword arguments:
230230
run_id -- GitHub Actions workflow run ID
@@ -249,8 +249,8 @@ def get_artifact_download_url_for_run(self, run_id):
249249
# No matching artifact found
250250
return None
251251

252-
def get_artifact(self, artifact_download_url):
253-
"""Download and unzip the artifact and return an object for the temporary directory containing it
252+
def get_artifact(self, artifact_download_url: str):
253+
"""Download and unzip the artifact and return an object for the temporary directory containing it.
254254
255255
Keyword arguments:
256256
artifact_download_url -- URL to download the artifact from GitHub
@@ -313,7 +313,7 @@ def get_sketches_reports(self, artifact_folder_object):
313313

314314
return sketches_reports
315315

316-
def generate_report(self, sketches_reports):
316+
def generate_report(self, sketches_reports) -> str:
317317
"""Return the Markdown for the deltas report comment.
318318
319319
Keyword arguments:
@@ -370,7 +370,7 @@ def generate_report(self, sketches_reports):
370370
logger.debug("Report:\n" + report_markdown)
371371
return report_markdown
372372

373-
def add_summary_report_row(self, report_data, fqbn_data):
373+
def add_summary_report_row(self, report_data, fqbn_data) -> None:
374374
"""Add a row to the summary report.
375375
376376
Keyword arguments:
@@ -433,7 +433,7 @@ def add_summary_report_row(self, report_data, fqbn_data):
433433
)
434434
)
435435

436-
def add_detailed_report_row(self, report_data, fqbn_data):
436+
def add_detailed_report_row(self, report_data, fqbn_data) -> None:
437437
"""Add a row to the detailed report.
438438
439439
Keyword arguments:
@@ -478,7 +478,7 @@ def add_detailed_report_row(self, report_data, fqbn_data):
478478
# Relative
479479
report_data[row_number][column_number + 1] = self.not_applicable_indicator
480480

481-
def get_summary_value(self, show_emoji, minimum, maximum):
481+
def get_summary_value(self, show_emoji: bool, minimum, maximum) -> str:
482482
"""Return the Markdown formatted text for a memory change data cell in the report table.
483483
484484
Keyword arguments:
@@ -517,8 +517,8 @@ def get_summary_value(self, show_emoji, minimum, maximum):
517517

518518
return value
519519

520-
def comment_report(self, pr_number, report_markdown):
521-
"""Submit the report as a comment on the PR thread
520+
def comment_report(self, pr_number: int, report_markdown: str) -> None:
521+
"""Submit the report as a comment on the PR thread.
522522
523523
Keyword arguments:
524524
pr_number -- pull request number to submit the report to
@@ -536,7 +536,7 @@ def comment_report(self, pr_number, report_markdown):
536536

537537
self.http_request(url=url, data=report_data)
538538

539-
def api_request(self, request, request_parameters="", page_number=1):
539+
def api_request(self, request: str, request_parameters: str = "", page_number: int = 1):
540540
"""Do a GitHub API request. Return a dictionary containing:
541541
json_data -- JSON object containing the response
542542
additional_pages -- indicates whether more pages of results remain (True, False)
@@ -552,7 +552,7 @@ def api_request(self, request, request_parameters="", page_number=1):
552552
return self.get_json_response(url="https://api.github.com/" + request + "?" + request_parameters + "&page="
553553
+ str(page_number) + "&per_page=100")
554554

555-
def get_json_response(self, url):
555+
def get_json_response(self, url: str):
556556
"""Load the specified URL and return a dictionary:
557557
json_data -- JSON object containing the response
558558
additional_pages -- indicates whether more pages of results remain (True, False)
@@ -587,7 +587,7 @@ def get_json_response(self, url):
587587
except Exception as exception:
588588
raise exception
589589

590-
def http_request(self, url, data=None):
590+
def http_request(self, url: str, data: str | None = None) -> dict[str]:
591591
"""Make a request and return a dictionary:
592592
read -- the response
593593
info -- headers
@@ -603,7 +603,7 @@ def http_request(self, url, data=None):
603603
"headers": response_object.info(),
604604
"url": response_object.geturl()}
605605

606-
def raw_http_request(self, url, data=None):
606+
def raw_http_request(self, url: str, data: str | None = None):
607607
"""Make a request and return an object containing the response.
608608
609609
Keyword arguments:
@@ -635,7 +635,7 @@ def raw_http_request(self, url, data=None):
635635
# Maximum retries reached without successfully opening URL
636636
raise TimeoutError("Maximum number of URL load retries exceeded")
637637

638-
def handle_rate_limiting(self):
638+
def handle_rate_limiting(self) -> None:
639639
"""Check whether the GitHub API request limit has been reached.
640640
If so, exit with exit status 0.
641641
"""
@@ -655,7 +655,7 @@ def handle_rate_limiting(self):
655655
sys.exit(0)
656656

657657

658-
def determine_urlopen_retry(exception):
658+
def determine_urlopen_retry(exception) -> bool:
659659
"""Determine whether the exception warrants another attempt at opening the URL.
660660
If so, delay then return True. Otherwise, return False.
661661
@@ -703,8 +703,8 @@ def determine_urlopen_retry(exception):
703703
return False
704704

705705

706-
def get_page_count(link_header):
707-
"""Return the number of pages of the API response
706+
def get_page_count(link_header: str | None) -> int:
707+
"""Return the number of pages of the API response.
708708
709709
Keyword arguments:
710710
link_header -- Link header of the HTTP response
@@ -723,7 +723,7 @@ def get_page_count(link_header):
723723
return page_count
724724

725725

726-
def get_report_column_number(report, column_heading):
726+
def get_report_column_number(report, column_heading: str) -> int:
727727
"""Return the column number of the given heading.
728728
729729
Keyword arguments:
@@ -752,8 +752,8 @@ def get_report_column_number(report, column_heading):
752752
return column_number
753753

754754

755-
def generate_markdown_table(row_list):
756-
"""Return the data formatted as a Markdown table
755+
def generate_markdown_table(row_list) -> str:
756+
"""Return the data formatted as a Markdown table.
757757
758758
Keyword arguments:
759759
row_list -- list containing the data
@@ -769,7 +769,7 @@ def generate_markdown_table(row_list):
769769
return markdown_table
770770

771771

772-
def generate_csv_table(row_list):
772+
def generate_csv_table(row_list) -> str:
773773
"""Return a string containing the supplied data formatted as CSV.
774774
775775
Keyword arguments:

0 commit comments

Comments
 (0)