Add Optional to remaining types (#37808)
More Optional typing Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
@@ -390,7 +390,7 @@ def split_code_into_blocks(
|
||||
|
||||
|
||||
def find_code_in_transformers(
|
||||
object_name: str, base_path: str = None, return_indices: bool = False
|
||||
object_name: str, base_path: Optional[str] = None, return_indices: bool = False
|
||||
) -> Union[str, Tuple[List[str], int, int]]:
|
||||
"""
|
||||
Find and return the source code of an object.
|
||||
@@ -491,7 +491,7 @@ def replace_code(code: str, replace_pattern: str) -> str:
|
||||
return code
|
||||
|
||||
|
||||
def find_code_and_splits(object_name: str, base_path: str, buffer: dict = None):
|
||||
def find_code_and_splits(object_name: str, base_path: str, buffer: Optional[dict] = None):
|
||||
"""Find the code of an object (specified by `object_name`) and split it into blocks.
|
||||
|
||||
Args:
|
||||
@@ -638,7 +638,9 @@ def check_codes_match(observed_code: str, theoretical_code: str) -> Optional[int
|
||||
diff_index += 1
|
||||
|
||||
|
||||
def is_copy_consistent(filename: str, overwrite: bool = False, buffer: dict = None) -> Optional[List[Tuple[str, int]]]:
|
||||
def is_copy_consistent(
|
||||
filename: str, overwrite: bool = False, buffer: Optional[dict] = None
|
||||
) -> Optional[List[Tuple[str, int]]]:
|
||||
"""
|
||||
Check if the code commented as a copy in a file matches the original.
|
||||
|
||||
@@ -831,7 +833,7 @@ def is_copy_consistent(filename: str, overwrite: bool = False, buffer: dict = No
|
||||
return diffs
|
||||
|
||||
|
||||
def check_copies(overwrite: bool = False, file: str = None):
|
||||
def check_copies(overwrite: bool = False, file: Optional[str] = None):
|
||||
"""
|
||||
Check every file is copy-consistent with the original. Also check the model list in the main README and other
|
||||
READMEs are consistent.
|
||||
|
||||
@@ -107,7 +107,7 @@ class Message:
|
||||
ci_title: str,
|
||||
model_results: Dict,
|
||||
additional_results: Dict,
|
||||
selected_warnings: List = None,
|
||||
selected_warnings: Optional[List] = None,
|
||||
prev_ci_artifacts=None,
|
||||
):
|
||||
self.title = title
|
||||
@@ -856,7 +856,7 @@ def retrieve_available_artifacts():
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def add_path(self, path: str, gpu: str = None):
|
||||
def add_path(self, path: str, gpu: Optional[str] = None):
|
||||
self.paths.append({"name": self.name, "path": path, "gpu": gpu})
|
||||
|
||||
_available_artifacts: Dict[str, Artifact] = {}
|
||||
|
||||
@@ -59,7 +59,7 @@ import re
|
||||
import tempfile
|
||||
from contextlib import contextmanager
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Tuple, Union
|
||||
from typing import Dict, List, Optional, Tuple, Union
|
||||
|
||||
from git import Repo
|
||||
|
||||
@@ -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: 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: Dict[str, List[str]] = None) -> Li
|
||||
return result
|
||||
|
||||
|
||||
def get_module_dependencies(module_fname: str, cache: 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
|
||||
@@ -953,7 +953,7 @@ def create_reverse_dependency_map() -> Dict[str, List[str]]:
|
||||
|
||||
|
||||
def create_module_to_test_map(
|
||||
reverse_map: Dict[str, List[str]] = None, filter_models: bool = False
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user