File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 22import mathutils
33
44from enum import Enum , auto
5- import os
5+ import keyword
66import re
7- import shutil
8- from typing import TextIO , Tuple
7+ from typing import Tuple
98
109IMAGE_DIR_NAME = "imgs"
1110
@@ -63,13 +62,19 @@ def clean_string(string: str, lower: bool = True) -> str:
6362 string (str): The input string
6463
6564 Returns:
66- clean_str : The input string with nasty characters converted to underscores
65+ string (str) : The input string ready to be used as a variable
6766 """
6867
6968 if lower :
7069 string = string .lower ()
71- clean_str = re .sub (r"[^a-zA-Z0-9_]" , '_' , string )
72- return clean_str
70+ string = re .sub (r"[^a-zA-Z0-9_]" , '_' , string )
71+
72+ if keyword .iskeyword (string ):
73+ string = "_" + string
74+ elif not (string [0 ].isalpha () or string [0 ] == '_' ):
75+ string = "_" + string
76+
77+ return string
7378
7479def enum_to_py_str (enum : str ) -> str :
7580 """
You can’t perform that action at this time.
0 commit comments