From b256516a8c28946d26df11987cb5e38a5a3bdfe2 Mon Sep 17 00:00:00 2001 From: Arthur <48595927+ArthurZucker@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:56:14 +0900 Subject: [PATCH] [`make fix-copies`] update and help (#29924) * add some help * style --- utils/check_copies.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/utils/check_copies.py b/utils/check_copies.py index 435f0bd89e..3756089575 100644 --- a/utils/check_copies.py +++ b/utils/check_copies.py @@ -309,7 +309,16 @@ def split_code_into_blocks( """ splits = [] # `indent - 4` is the indent level of the target class/func header - target_block_name = re.search(rf"^{' ' * (indent - 4)}((class|def)\s+\S+)(\(|\:)", lines[start_index]).groups()[0] + try: + target_block_name = re.search( + rf"^{' ' * (indent - 4)}((class|def)\s+\S+)(\(|\:)", lines[start_index] + ).groups()[0] + except ValueError: + raise ValueError( + f"Tried to split a class or function. It did not work. Error comes from line {start_index}: ```\n" + + "".join(lines[start_index:end_index]) + + "```\n" + ) # from now on, the `block` means inner blocks unless explicitly specified indent_str = " " * indent