Add Optional to remaining types (#37808)

More Optional typing

Signed-off-by: cyy <cyyever@outlook.com>
This commit is contained in:
Yuanyuan Chen
2025-04-28 21:20:45 +08:00
committed by GitHub
parent 1a9188a54e
commit da4ff2a5f5
206 changed files with 553 additions and 531 deletions

View File

@@ -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.