Skip to content

Commit 0dc8ffe

Browse files
committed
Add tests for strict dunder typing mode
1 parent 8657bbd commit 0dc8ffe

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

mypyc/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def mypycify(
523523
separate=separate is not False,
524524
target_dir=target_dir,
525525
include_runtime_files=include_runtime_files,
526-
strict_dunders_typing=strict_dunder_typing,
526+
strict_dunder_typing=strict_dunder_typing,
527527
)
528528

529529
# Generate all the actual important C code

mypyc/options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(
1414
include_runtime_files: bool | None = None,
1515
capi_version: tuple[int, int] | None = None,
1616
python_version: tuple[int, int] | None = None,
17-
strict_dunders_typing: bool = False,
17+
strict_dunder_typing: bool = False,
1818
) -> None:
1919
self.strip_asserts = strip_asserts
2020
self.multi_file = multi_file
@@ -37,4 +37,4 @@ def __init__(
3737
# By enabling this option, this convention is no longer valid and the dunder
3838
# will assume the return type of the method strictly, which can lead to
3939
# more optimization opportunities.
40-
self.strict_dunders_typing = strict_dunders_typing
40+
self.strict_dunders_typing = strict_dunder_typing

mypyc/test/test_run.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class TestRun(MypycDataSuite):
140140
optional_out = True
141141
multi_file = False
142142
separate = False # If True, using separate (incremental) compilation
143+
strict_dunder_typing = False
143144

144145
def run_case(self, testcase: DataDrivenTestCase) -> None:
145146
# setup.py wants to be run from the root directory of the package, which we accommodate
@@ -232,7 +233,11 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) ->
232233
groups = construct_groups(sources, separate, len(module_names) > 1)
233234

234235
try:
235-
compiler_options = CompilerOptions(multi_file=self.multi_file, separate=self.separate)
236+
compiler_options = CompilerOptions(
237+
multi_file=self.multi_file,
238+
separate=self.separate,
239+
strict_dunder_typing=self.strict_dunder_typing,
240+
)
236241
result = emitmodule.parse_and_typecheck(
237242
sources=sources,
238243
options=options,
@@ -401,6 +406,14 @@ class TestRunSeparate(TestRun):
401406
files = ["run-multimodule.test", "run-mypy-sim.test"]
402407

403408

409+
class TestRunStrictDunderTyping(TestRun):
410+
"""Run the tests with strict dunder typing."""
411+
412+
strict_dunder_typing = True
413+
test_name_suffix = "_dunder_typing"
414+
files = ["run-dunders.test", "run-floats.test"]
415+
416+
404417
def fix_native_line_number(message: str, fnam: str, delta: int) -> str:
405418
"""Update code locations in test case output to point to the .test file.
406419

0 commit comments

Comments
 (0)