Fixit
Fixit copied to clipboard
Passing no providers to FullRepoMetadataConfig causes exception
My ultimate goal is to use Fixit without Pyre, and without having to pass timeout=0
to the TypeInferenceProvider to force a breakage in the pyre subprocess call.
Created a simple repro:
from pathlib import Path
import logging
import sys
import libcst as cst
from fixit._version import FIXIT_VERSION
from fixit.common.config import get_lint_config
from fixit.common.config import get_rules_from_config
from fixit.common.full_repo_metadata import FullRepoMetadataConfig, get_repo_caches
from fixit.rule_lint_engine import lint_file
from libcst.metadata import MetadataWrapper, TypeInferenceProvider
def main(filename):
full_repo_metadata_config = FullRepoMetadataConfig(
providers=set(), # <--- passing in no provider here instead of TypeInferenceProvider
timeout_seconds=120, # <--- If I were passing TypeInferenceProvider I would set this to 0
logger=logging.getLogger("Metadata"),
)
with open(filename, "rb") as f:
source = f.read()
metadata_caches = get_repo_caches([filename], full_repo_metadata_config)
try:
cst_wrapper = MetadataWrapper(
cst.parse_module(source),
True,
metadata_caches[filename],
)
except Exception:
cst_wrapper = None
rules = get_rules_from_config()
config = get_lint_config()
results = lint_file(
Path(filename),
source,
rules=rules,
config=config,
cst_wrapper=cst_wrapper,
find_unused_suppressions=True,
)
print(results)
if __name__ == "__main__":
filename = sys.argv[0]
main(filename)
Running this file results in:
(fixit-env) lisroach@lisroach-mbp Fixit % python3 hey.py hey.py
Traceback (most recent call last):
File "hey.py", line 45, in <module>
main(filename)
File "hey.py", line 39, in main
find_unused_suppressions=True,
File "/Users/lisroach/Fixit/fixit/rule_lint_engine.py", line 115, in lint_file
_visit_cst_rules_with_context(cst_wrapper, cst_rules, cst_context)
File "/Users/lisroach/Fixit/fixit/rule_lint_engine.py", line 50, in _visit_cst_rules_with_context
rule_instances, before_visit=before_visit, after_leave=after_leave
File "/Users/lisroach/fixit-env/lib/python3.7/site-packages/libcst/metadata/wrapper.py", line 222, in visit_batched
stack.enter_context(v.resolve(self))
File "/opt/homebrew/Cellar/python37/3.7.5_3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 427, in enter_context
result = _cm_type.__enter__(cm)
File "/opt/homebrew/Cellar/python37/3.7.5_3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/contextlib.py", line 112, in __enter__
return next(self.gen)
File "/Users/lisroach/fixit-env/lib/python3.7/site-packages/libcst/_metadata_dependent.py", line 85, in resolve
self.metadata = wrapper.resolve_many(self.get_inherited_dependencies())
File "/Users/lisroach/fixit-env/lib/python3.7/site-packages/libcst/metadata/wrapper.py", line 196, in resolve_many
_resolve_impl(self, providers)
File "/Users/lisroach/fixit-env/lib/python3.7/site-packages/libcst/metadata/wrapper.py", line 97, in _resolve_impl
p(wrapper._cache.get(p)) if p.gen_cache else p() for p in batchable
File "/Users/lisroach/fixit-env/lib/python3.7/site-packages/libcst/metadata/wrapper.py", line 97, in <listcomp>
p(wrapper._cache.get(p)) if p.gen_cache else p() for p in batchable
File "/Users/lisroach/fixit-env/lib/python3.7/site-packages/libcst/metadata/type_inference_provider.py", line 75, in __init__
super().__init__(cache)
File "/Users/lisroach/fixit-env/lib/python3.7/site-packages/libcst/metadata/base_provider.py", line 69, in __init__
f"Cache is required for initializing {self.__class__.__name__}."