Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes pyre type-check errors. #196

Merged
merged 3 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions fixit/common/generate_pyre_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import json
import tempfile
from pathlib import Path
from typing import cast
from typing import List, cast

from libcst.metadata.type_inference_provider import (
PyreData,
Expand All @@ -33,10 +33,10 @@ class RuleTypeError(Exception):


class PyreQueryError(Exception):
def __init__(self, command: str, message: str) -> None:
def __init__(self, command: List[str], message: str) -> None:
super().__init__(
"Unable to infer types from temporary file. "
+ f"Command `{command}` returned with the following message: {message}."
+ f"Command `{' '.join(command)}` returned with the following message: {message}."
)


Expand All @@ -50,7 +50,7 @@ def gen_types_for_test_case(source_code: str, dest_path: Path) -> None:
temp.write(_dedent(source_code))
temp.seek(0)

cmd = f'''pyre query "types(path='{temp.name}')"'''
cmd = ["pyre", "query", f'''"types(path='{temp.name}')"''']
stdout, stderr, return_code = run_command(cmd)
if return_code != 0:
raise PyreQueryError(cmd, f"{stdout}\n{stderr}")
Expand All @@ -72,7 +72,7 @@ def gen_types(rule: CstLintRule, rule_fixture_dir: Path) -> None:
if hasattr(rule, "VALID") or hasattr(rule, "INVALID"):
print("Starting pyre server")

stdout, stderr, return_code = run_command("pyre start")
stdout, stderr, return_code = run_command(["pyre", "start"])
if return_code != 0:
print(stdout)
print(stderr)
Expand All @@ -86,7 +86,7 @@ def gen_types(rule: CstLintRule, rule_fixture_dir: Path) -> None:
for idx, invalid_tc in enumerate(getattr(rule, "INVALID")):
path: Path = rule_fixture_dir / f"{class_name}_INVALID_{idx}.json"
gen_types_for_test_case(source_code=invalid_tc.code, dest_path=path)
run_command("pyre stop")
run_command(["pyre", "stop"])


def get_fixture_path(
Expand Down
4 changes: 2 additions & 2 deletions fixit/rules/cls_in_classmethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class _RenameTransformer(cst.CSTTransformer):
def __init__(
self, names: List[Union[cst.Name, cst.Attribute]], new_name: str
self, names: List[Union[cst.Name, cst.BaseString, cst.Attribute]], new_name: str
) -> None:
self.names = names
self.new_name = new_name
Expand Down Expand Up @@ -269,7 +269,7 @@ def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
self.report(node)
return

refs: List[Union[cst.Name, cst.Attribute]] = []
refs: List[Union[cst.Name, cst.Attribute, cst.BaseString]] = []
assignments = scope[p0_name.value]
for a in assignments:
if isinstance(a, Assignment):
Expand Down