Skip to content

Commit f79ae69

Browse files
authored
Speed up pythoneval tests (#16559)
Skip slow and unnecessary overload checks in stdlib stubs in these tests. These checks already seem to be skipped in most other contexts, but because pythoneval tests use `--no-silence-site-packages`, the checks were enabled. This makes pythoneval tests about 13% faster on my Linux desktop, and it should also speed up CI a bit.
1 parent 92fa548 commit f79ae69

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

mypy/checker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,9 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
709709
# At this point we should have set the impl already, and all remaining
710710
# items are decorators
711711

712-
if self.msg.errors.file in self.msg.errors.ignored_files:
712+
if self.msg.errors.file in self.msg.errors.ignored_files or (
713+
self.is_typeshed_stub and self.options.test_env
714+
):
713715
# This is a little hacky, however, the quadratic check here is really expensive, this
714716
# method has no side effects, so we should skip it if we aren't going to report
715717
# anything. In some other places we swallow errors in stubs, but this error is very

mypy/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,8 @@ def add_invertible_flag(
11351135
parser.add_argument("--dump-graph", action="store_true", help=argparse.SUPPRESS)
11361136
# --semantic-analysis-only does exactly that.
11371137
parser.add_argument("--semantic-analysis-only", action="store_true", help=argparse.SUPPRESS)
1138+
# Some tests use this to tell mypy that we are running a test.
1139+
parser.add_argument("--test-env", action="store_true", help=argparse.SUPPRESS)
11381140
# --local-partial-types disallows partial types spanning module top level and a function
11391141
# (implicitly defined in fine-grained incremental mode)
11401142
parser.add_argument("--local-partial-types", action="store_true", help=argparse.SUPPRESS)

mypy/options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ def __init__(self) -> None:
321321
# Use stub builtins fixtures to speed up tests
322322
self.use_builtins_fixtures = False
323323

324+
# This should only be set when running certain mypy tests.
325+
# Use this sparingly to avoid tests diverging from non-test behavior.
326+
self.test_env = False
327+
324328
# -- experimental options --
325329
self.shadow_file: list[list[str]] | None = None
326330
self.show_column_numbers: bool = False

mypy/test/testpythoneval.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
5353
"--hide-error-codes",
5454
"--allow-empty-bodies",
5555
"--force-uppercase-builtins",
56+
"--test-env", # Speeds up some checks
5657
]
5758
interpreter = python3_path
5859
mypy_cmdline.append(f"--python-version={'.'.join(map(str, PYTHON3_VERSION))}")

0 commit comments

Comments
 (0)