No more Tuple, List, Dict (#38797)
* No more Tuple, List, Dict * make fixup * More style fixes * Docstring fixes with regex replacement * Trigger tests * Redo fixes after rebase * Fix copies * [test all] * update * [test all] * update * [test all] * make style after rebase * Patch the hf_argparser test * Patch the hf_argparser test * style fixes * style fixes * style fixes * Fix docstrings in Cohere test * [test all] --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
This commit is contained in:
@@ -59,7 +59,7 @@ import re
|
||||
import tempfile
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Tuple, Union
|
||||
from typing import Optional, Union
|
||||
|
||||
from git import Repo
|
||||
|
||||
@@ -182,7 +182,7 @@ def keep_doc_examples_only(content: str) -> str:
|
||||
return "\n".join(lines_to_keep)
|
||||
|
||||
|
||||
def get_all_tests() -> List[str]:
|
||||
def get_all_tests() -> list[str]:
|
||||
"""
|
||||
Walks the `tests` folder to return a list of files/subfolders. This is used to split the tests to run when using
|
||||
parallelism. The split is:
|
||||
@@ -263,7 +263,7 @@ def diff_contains_doc_examples(repo: Repo, branching_point: str, filename: str)
|
||||
return old_content_clean != new_content_clean
|
||||
|
||||
|
||||
def get_impacted_files_from_tiny_model_summary(diff_with_last_commit: bool = False) -> List[str]:
|
||||
def get_impacted_files_from_tiny_model_summary(diff_with_last_commit: bool = False) -> list[str]:
|
||||
"""
|
||||
Return a list of python modeling files that are impacted by the changes of `tiny_model_summary.json` in between:
|
||||
|
||||
@@ -379,7 +379,7 @@ def get_impacted_files_from_tiny_model_summary(diff_with_last_commit: bool = Fal
|
||||
return sorted(files)
|
||||
|
||||
|
||||
def get_diff(repo: Repo, base_commit: str, commits: List[str]) -> List[str]:
|
||||
def get_diff(repo: Repo, base_commit: str, commits: list[str]) -> list[str]:
|
||||
"""
|
||||
Get the diff between a base commit and one or several commits.
|
||||
|
||||
@@ -421,7 +421,7 @@ def get_diff(repo: Repo, base_commit: str, commits: List[str]) -> List[str]:
|
||||
return code_diff
|
||||
|
||||
|
||||
def get_modified_python_files(diff_with_last_commit: bool = False) -> List[str]:
|
||||
def get_modified_python_files(diff_with_last_commit: bool = False) -> list[str]:
|
||||
"""
|
||||
Return a list of python files that have been modified between:
|
||||
|
||||
@@ -451,7 +451,7 @@ def get_modified_python_files(diff_with_last_commit: bool = False) -> List[str]:
|
||||
return get_diff(repo, repo.head.commit, parent_commits)
|
||||
|
||||
|
||||
def get_diff_for_doctesting(repo: Repo, base_commit: str, commits: List[str]) -> List[str]:
|
||||
def get_diff_for_doctesting(repo: Repo, base_commit: str, commits: list[str]) -> list[str]:
|
||||
"""
|
||||
Get the diff in doc examples between a base commit and one or several commits.
|
||||
|
||||
@@ -492,7 +492,7 @@ def get_diff_for_doctesting(repo: Repo, base_commit: str, commits: List[str]) ->
|
||||
return code_diff
|
||||
|
||||
|
||||
def get_all_doctest_files() -> List[str]:
|
||||
def get_all_doctest_files() -> list[str]:
|
||||
"""
|
||||
Return the complete list of python and Markdown files on which we run doctest.
|
||||
|
||||
@@ -525,7 +525,7 @@ def get_all_doctest_files() -> List[str]:
|
||||
return sorted(test_files_to_run)
|
||||
|
||||
|
||||
def get_new_doctest_files(repo, base_commit, branching_commit) -> List[str]:
|
||||
def get_new_doctest_files(repo, base_commit, branching_commit) -> list[str]:
|
||||
"""
|
||||
Get the list of files that were removed from "utils/not_doctested.txt", between `base_commit` and
|
||||
`branching_commit`.
|
||||
@@ -552,7 +552,7 @@ def get_new_doctest_files(repo, base_commit, branching_commit) -> List[str]:
|
||||
return []
|
||||
|
||||
|
||||
def get_doctest_files(diff_with_last_commit: bool = False) -> List[str]:
|
||||
def get_doctest_files(diff_with_last_commit: bool = False) -> list[str]:
|
||||
"""
|
||||
Return a list of python and Markdown files where doc example have been modified between:
|
||||
|
||||
@@ -621,7 +621,7 @@ _re_single_line_direct_imports = re.compile(r"(?:^|\n)\s*from\s+transformers(\S*
|
||||
_re_multi_line_direct_imports = re.compile(r"(?:^|\n)\s*from\s+transformers(\S*)\s+import\s+\(([^\)]+)\)")
|
||||
|
||||
|
||||
def extract_imports(module_fname: str, cache: Optional[Dict[str, List[str]]] = None) -> List[str]:
|
||||
def extract_imports(module_fname: str, cache: Optional[dict[str, list[str]]] = None) -> list[str]:
|
||||
"""
|
||||
Get the imports a given module makes.
|
||||
|
||||
@@ -703,7 +703,7 @@ def extract_imports(module_fname: str, cache: Optional[Dict[str, List[str]]] = N
|
||||
return result
|
||||
|
||||
|
||||
def get_module_dependencies(module_fname: str, cache: Optional[Dict[str, List[str]]] = None) -> List[str]:
|
||||
def get_module_dependencies(module_fname: str, cache: Optional[dict[str, list[str]]] = None) -> list[str]:
|
||||
"""
|
||||
Refines the result of `extract_imports` to remove subfolders and get a proper list of module filenames: if a file
|
||||
as an import `from utils import Foo, Bar`, with `utils` being a subfolder containing many files, this will traverse
|
||||
@@ -786,7 +786,7 @@ def get_module_dependencies(module_fname: str, cache: Optional[Dict[str, List[st
|
||||
return dependencies
|
||||
|
||||
|
||||
def create_reverse_dependency_tree() -> List[Tuple[str, str]]:
|
||||
def create_reverse_dependency_tree() -> list[tuple[str, str]]:
|
||||
"""
|
||||
Create a list of all edges (a, b) which mean that modifying a impacts b with a going over all module and test files.
|
||||
"""
|
||||
@@ -800,7 +800,7 @@ def create_reverse_dependency_tree() -> List[Tuple[str, str]]:
|
||||
return list(set(edges))
|
||||
|
||||
|
||||
def get_tree_starting_at(module: str, edges: List[Tuple[str, str]]) -> List[Union[str, List[str]]]:
|
||||
def get_tree_starting_at(module: str, edges: list[tuple[str, str]]) -> list[Union[str, list[str]]]:
|
||||
"""
|
||||
Returns the tree starting at a given module following all edges.
|
||||
|
||||
@@ -861,7 +861,7 @@ def print_tree_deps_of(module, all_edges=None):
|
||||
print(line[0])
|
||||
|
||||
|
||||
def init_test_examples_dependencies() -> Tuple[Dict[str, List[str]], List[str]]:
|
||||
def init_test_examples_dependencies() -> tuple[dict[str, list[str]], list[str]]:
|
||||
"""
|
||||
The test examples do not import from the examples (which are just scripts, not modules) so we need some extra
|
||||
care initializing the dependency map, which is the goal of this function. It initializes the dependency map for
|
||||
@@ -897,7 +897,7 @@ def init_test_examples_dependencies() -> Tuple[Dict[str, List[str]], List[str]]:
|
||||
return test_example_deps, all_examples
|
||||
|
||||
|
||||
def create_reverse_dependency_map() -> Dict[str, List[str]]:
|
||||
def create_reverse_dependency_map() -> dict[str, list[str]]:
|
||||
"""
|
||||
Create the dependency map from module/test filename to the list of modules/tests that depend on it recursively.
|
||||
|
||||
@@ -953,8 +953,8 @@ def create_reverse_dependency_map() -> Dict[str, List[str]]:
|
||||
|
||||
|
||||
def create_module_to_test_map(
|
||||
reverse_map: Optional[Dict[str, List[str]]] = None, filter_models: bool = False
|
||||
) -> Dict[str, List[str]]:
|
||||
reverse_map: Optional[dict[str, list[str]]] = None, filter_models: bool = False
|
||||
) -> dict[str, list[str]]:
|
||||
"""
|
||||
Extract the tests from the reverse_dependency_map and potentially filters the model tests.
|
||||
|
||||
@@ -1108,7 +1108,7 @@ def infer_tests_to_run(
|
||||
f.write(" ".join(doctest_list))
|
||||
|
||||
|
||||
def filter_tests(output_file: str, filters: List[str]):
|
||||
def filter_tests(output_file: str, filters: list[str]):
|
||||
"""
|
||||
Reads the content of the output file and filters out all the tests in a list of given folders.
|
||||
|
||||
@@ -1135,7 +1135,7 @@ def filter_tests(output_file: str, filters: List[str]):
|
||||
f.write(" ".join(test_files))
|
||||
|
||||
|
||||
def parse_commit_message(commit_message: str) -> Dict[str, bool]:
|
||||
def parse_commit_message(commit_message: str) -> dict[str, bool]:
|
||||
"""
|
||||
Parses the commit message to detect if a command is there to skip, force all or part of the CI.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user