From 122a04294ac7881da429784181bd365540cc4ffc Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:02:10 +0000 Subject: [PATCH 1/2] refactor: fix dangerous default argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not use a mutable like `list` or `dictionary` as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well. --- manimlib/utils/strings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/manimlib/utils/strings.py b/manimlib/utils/strings.py index b986577d21..a54c1cc376 100644 --- a/manimlib/utils/strings.py +++ b/manimlib/utils/strings.py @@ -10,7 +10,9 @@ def to_camel_case(name): ]) -def initials(name, sep_values=[" ", "_"]): +def initials(name, sep_values=None): + if sep_values is None: + sep_values = [" ", "_"] return "".join([ (s[0] if s else "") for s in re.split("|".join(sep_values), name) From 47a8b0fa657d3e28df2041e67aaf49bdfa9bd378 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:02:27 +0000 Subject: [PATCH 2/2] style: format code with Black This commit fixes the style issues introduced in 122a042 according to the output from Black. Details: https://github.com/sanket-deepsource/manim/pull/2 --- manimlib/utils/strings.py | 43 ++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/manimlib/utils/strings.py b/manimlib/utils/strings.py index a54c1cc376..20612a25eb 100644 --- a/manimlib/utils/strings.py +++ b/manimlib/utils/strings.py @@ -4,19 +4,20 @@ def to_camel_case(name): - return "".join([ - [c for c in part if c not in string.punctuation + string.whitespace].capitalize() - for part in name.split("_") - ]) + return "".join( + [ + [ + c for c in part if c not in string.punctuation + string.whitespace + ].capitalize() + for part in name.split("_") + ] + ) def initials(name, sep_values=None): if sep_values is None: sep_values = [" ", "_"] - return "".join([ - (s[0] if s else "") - for s in re.split("|".join(sep_values), name) - ]) + return "".join([(s[0] if s else "") for s in re.split("|".join(sep_values), name)]) def camel_case_initials(name): @@ -39,10 +40,16 @@ def split_string_to_isolate_substrings(full_string, *substrings_to_isolate): if len(substrings_to_isolate) == 0: return [full_string] substring_to_isolate = substrings_to_isolate[0] - all_substrings = list(it.chain(*list(zip( - full_string.split(substring_to_isolate), - it.repeat(substring_to_isolate) - )))) + all_substrings = list( + it.chain( + *list( + zip( + full_string.split(substring_to_isolate), + it.repeat(substring_to_isolate), + ) + ) + ) + ) all_substrings.pop(-1) all_substrings = [s for s in all_substrings if s != ""] return split_string_list_to_isolate_substrings( @@ -55,7 +62,11 @@ def split_string_list_to_isolate_substrings(string_list, *substrings_to_isolate) Similar to split_string_to_isolate_substrings, but the first argument is a list of strings, thought of as something already broken up a bit. """ - return list(it.chain(*[ - split_string_to_isolate_substrings(s, *substrings_to_isolate) - for s in string_list - ])) + return list( + it.chain( + *[ + split_string_to_isolate_substrings(s, *substrings_to_isolate) + for s in string_list + ] + ) + )