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

Make the projects be their own repr! #94

Merged
merged 9 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 5 additions & 1 deletion mypy_primer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ def select_projects() -> list[Project]:
if ARGS.local_project:
return [Project.from_location(ARGS.local_project)]

project_iter: Iterator[Project] = iter(p for p in get_projects())
project_iter: Iterator[Project] = iter(
p
for p in get_projects()
if not (p.min_python_version and sys.version_info < p.min_python_version)
)
if ARGS.type_checker == "pyright":
project_iter = iter(p for p in project_iter if p.pyright_cmd is not None)
if ARGS.project_selector:
Expand Down
27 changes: 25 additions & 2 deletions mypy_primer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
from mypy_primer.globals import ctx
from mypy_primer.utils import BIN_DIR, Style, debug_print, run

extra_dataclass_args = {"kw_only": True} if sys.version_info >= (3, 10) else {}

@dataclass(frozen=True)

@dataclass(frozen=True, **extra_dataclass_args)
class Project:
location: str
mypy_cmd: str
revision: str | None = None
min_python_version: tuple[int, int] | None = None
pip_cmd: str | None = None
# if expected_success, there is a recent version of mypy which passes cleanly
expected_mypy_success: bool = False
Expand All @@ -34,6 +37,26 @@ class Project:
pyright_cmd: str | None = None
expected_pyright_success: bool = False

# custom __repr__ that omits defaults.
def __repr__(self) -> str:
result = f"Project(location={self.location!r}, mypy_cmd={self.mypy_cmd!r}"
if self.pyright_cmd:
result += f", pyright_cmd={self.pyright_cmd!r}"
if self.pip_cmd:
result += f", pip_cmd={self.pip_cmd!r}"
if self.expected_mypy_success:
result += f", expected_mypy_success={self.expected_mypy_success!r}"
if self.expected_pyright_success:
result += f", expected_pyright_success={self.expected_pyright_success!r}"
if self.mypy_cost != 3:
result += f", mypy_cost={self.mypy_cost!r}"
if self.revision:
result += f", revision={self.revision!r}"
if self.min_python_version:
result += f", min_python_version={self.min_python_version!r}"
result += ")"
return result

@property
def name(self) -> str:
return Path(self.location).name
Expand Down Expand Up @@ -322,7 +345,7 @@ def format_concise(self) -> str:
ret += (
f": typechecking got {runtime_ratio:.2f}x {speed} "
f"({self.old_result.runtime:.1f}s -> {self.new_result.runtime:.1f}s)\n"
f"(Performance measurements are based on a single noisy sample)"
"(Performance measurements are based on a single noisy sample)"
)
if self.diff:
ret += "\n" + self.diff
Expand Down
Loading