Skip to content

Commit ddc180f

Browse files
authored
Augmented calls to yaml.load to use the safe loader. (#3817)
I fixed two calls to yaml.load to explicitly use the Safe Loader. I copied the code from other repos that do it this way.
1 parent a9a1355 commit ddc180f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

build_tools/autogen_ltc_backend.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
TORCHGEN_DIR = Path(torchgen.__path__[0]).resolve()
3131
TORCH_MLIR_DIR = Path(__file__).resolve().parent.parent
3232

33+
# Safely load fast C Yaml loader if it is are available
34+
try:
35+
from yaml import CSafeLoader as Loader
36+
except ImportError:
37+
from yaml import SafeLoader as Loader #type:ignore[assignment, misc]
3338

3439
def reindent(text, prefix=""):
3540
return indent(dedent(text), prefix)
@@ -175,7 +180,7 @@ def generate_native_functions(self):
175180
)
176181
ts_native_yaml = None
177182
if ts_native_yaml_path.exists():
178-
ts_native_yaml = yaml.load(ts_native_yaml_path.read_text(), yaml.CLoader)
183+
ts_native_yaml = yaml.load(ts_native_yaml_path.read_text(), Loader)
179184
else:
180185
logging.warning(
181186
f"Could not find `ts_native_functions.yaml` at {ts_native_yaml_path}"
@@ -208,7 +213,7 @@ def get_opnames(ops):
208213
)
209214

210215
with self.config_path.open() as f:
211-
config = yaml.load(f, yaml.CLoader)
216+
config = yaml.load(f, Loader)
212217

213218
# List of unsupported ops in LTC autogen because of some error
214219
blacklist = set(config.get("blacklist", []))

0 commit comments

Comments
 (0)