Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2ceb8d

Browse files
A5rocksAkuli
andauthored
Make the projects be their own repr! (#94)
Co-authored-by: Akuli <[email protected]>
1 parent f79faa9 commit e2ceb8d

5 files changed

Lines changed: 156 additions & 114 deletions

File tree

mypy_primer/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def select_projects() -> list[Project]:
112112
if ARGS.local_project:
113113
return [Project.from_location(ARGS.local_project)]
114114

115-
project_iter: Iterator[Project] = iter(p for p in get_projects())
115+
project_iter: Iterator[Project] = iter(
116+
p
117+
for p in get_projects()
118+
if not (p.min_python_version and sys.version_info < p.min_python_version)
119+
)
116120
if ARGS.type_checker == "pyright":
117121
project_iter = iter(p for p in project_iter if p.pyright_cmd is not None)
118122
if ARGS.project_selector:

mypy_primer/model.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
from mypy_primer.globals import ctx
2020
from mypy_primer.utils import BIN_DIR, Style, debug_print, run
2121

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

23-
@dataclass(frozen=True)
24+
25+
@dataclass(frozen=True, **extra_dataclass_args)
2426
class Project:
2527
location: str
2628
mypy_cmd: str
2729
revision: str | None = None
30+
min_python_version: tuple[int, int] | None = None
2831
pip_cmd: str | None = None
2932
# if expected_success, there is a recent version of mypy which passes cleanly
3033
expected_mypy_success: bool = False
@@ -34,6 +37,26 @@ class Project:
3437
pyright_cmd: str | None = None
3538
expected_pyright_success: bool = False
3639

40+
# custom __repr__ that omits defaults.
41+
def __repr__(self) -> str:
42+
result = f"Project(location={self.location!r}, mypy_cmd={self.mypy_cmd!r}"
43+
if self.pyright_cmd:
44+
result += f", pyright_cmd={self.pyright_cmd!r}"
45+
if self.pip_cmd:
46+
result += f", pip_cmd={self.pip_cmd!r}"
47+
if self.expected_mypy_success:
48+
result += f", expected_mypy_success={self.expected_mypy_success!r}"
49+
if self.expected_pyright_success:
50+
result += f", expected_pyright_success={self.expected_pyright_success!r}"
51+
if self.mypy_cost != 3:
52+
result += f", mypy_cost={self.mypy_cost!r}"
53+
if self.revision:
54+
result += f", revision={self.revision!r}"
55+
if self.min_python_version:
56+
result += f", min_python_version={self.min_python_version!r}"
57+
result += ")"
58+
return result
59+
3760
@property
3861
def name(self) -> str:
3962
return Path(self.location).name
@@ -324,7 +347,7 @@ def format_concise(self) -> str:
324347
ret += (
325348
f": typechecking got {runtime_ratio:.2f}x {speed} "
326349
f"({self.old_result.runtime:.1f}s -> {self.new_result.runtime:.1f}s)\n"
327-
f"(Performance measurements are based on a single noisy sample)"
350+
"(Performance measurements are based on a single noisy sample)"
328351
)
329352
if self.diff:
330353
ret += "\n" + self.diff

0 commit comments

Comments
 (0)