2020from .loader import StrictSourceFileLoader
2121
2222
23+ OPT_OUT_LIST : set [str ] | None = None
24+ OPT_IN_LIST : set [str ] | None = None
25+
26+
2327class PyreflyLoader (StrictSourceFileLoader ):
2428 pyrefly_type_dir : str | None = None
2529
@@ -40,8 +44,8 @@ def ensure_compiler(
4044 else :
4145 pyrefly = None
4246 comp = cls .compiler = PyreflyCompiler (
43- static_opt_out = None ,
44- static_opt_in = None ,
47+ static_opt_out = OPT_OUT_LIST ,
48+ static_opt_in = OPT_IN_LIST ,
4549 path = path ,
4650 stub_path = stub_path ,
4751 allow_list_prefix = allow_list_prefix ,
@@ -54,6 +58,10 @@ def ensure_compiler(
5458 return comp
5559
5660 def should_force_strict (self ) -> bool :
61+ if OPT_IN_LIST is not None :
62+ return self .name in OPT_IN_LIST
63+ if OPT_OUT_LIST is not None :
64+ return self .name not in OPT_OUT_LIST
5765 return True
5866
5967
@@ -112,11 +120,20 @@ def _get_supported_file_loaders(
112120 return [extensions , source , bytecode ]
113121
114122
115- def install (enable_patching : bool = False , pyrefly_type_dir : str | None = None ) -> None :
123+ def install (
124+ enable_patching : bool = False ,
125+ pyrefly_type_dir : str | None = None ,
126+ opt_in_list : set [str ] | None = None ,
127+ opt_out_list : set [str ] | None = None ,
128+ ) -> None :
116129 """Installs a loader which is capable of loading and validating strict modules"""
117130 PyreflyLoader .pyrefly_type_dir = pyrefly_type_dir
118131 supported_loaders = _get_supported_file_loaders (enable_patching )
119132
133+ global OPT_IN_LIST , OPT_OUT_LIST
134+ OPT_IN_LIST = opt_in_list
135+ OPT_OUT_LIST = opt_out_list
136+
120137 for index , hook in enumerate (sys .path_hooks ):
121138 if not isinstance (hook , type ):
122139 sys .path_hooks .insert (index , FileFinder .path_hook (* supported_loaders ))
0 commit comments