MCPcopy Create free account
hub / github.com/apache/fory / _sanitize_function_name

Function _sanitize_function_name

python/pyfory/codegen.py:103–117  ·  view source on GitHub ↗

Sanitize function names by replacing invalid characters with valid ones. This is needed because function names with special characters like angle brackets are not valid Python syntax.

(name: str)

Source from the content-addressed store, hash-verified

101
102
103def _sanitize_function_name(name: str) -> str:
104 """
105 Sanitize function names by replacing invalid characters with valid ones.
106 This is needed because function names with special characters like angle brackets
107 are not valid Python syntax.
108 """
109 # 1) Replace every non‐identifier character with underscore
110 sanitized = re.sub(r"[^0-9A-Za-z_]", "_", name)
111 # 2) Prevent leading digit
112 if re.match(r"^\d", sanitized):
113 sanitized = "_" + sanitized
114 # 3) Avoid plain keywords
115 if keyword.iskeyword(sanitized):
116 sanitized = "_" + sanitized
117 return sanitized
118
119
120def compile_function(

Callers 2

compile_functionFunction · 0.85
_generate_filenameFunction · 0.85

Calls 2

subMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected