Skip to content

Commit 8575747

Browse files
committed
Add more testing
1 parent fa29931 commit 8575747

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

mypyc/irbuild/env_class.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def g() -> int:
2020
from mypy.nodes import Argument, FuncDef, SymbolNode, Var
2121
from mypyc.common import BITMAP_BITS, ENV_ATTR_NAME, SELF_NAME, bitmap_name
2222
from mypyc.ir.class_ir import ClassIR
23-
from mypyc.ir.func_ir import FuncSignature
2423
from mypyc.ir.ops import Call, GetAttr, SetAttr, Value
2524
from mypyc.ir.rtypes import RInstance, bitmap_rprimitive, object_rprimitive
2625
from mypyc.irbuild.builder import IRBuilder, SymbolTarget
@@ -57,17 +56,17 @@ class is generated, the function environment has not yet been
5756
return env_class
5857

5958

60-
def finalize_env_class(builder: IRBuilder, sig: FuncSignature) -> None:
59+
def finalize_env_class(builder: IRBuilder) -> None:
6160
"""Generate, instantiate, and set up the environment of an environment class."""
6261
instantiate_env_class(builder)
6362

6463
# Iterate through the function arguments and replace local definitions (using registers)
6564
# that were previously added to the environment with references to the function's
6665
# environment class.
6766
if builder.fn_info.is_nested:
68-
add_args_to_env(builder, sig, local=False, base=builder.fn_info.callable_class)
67+
add_args_to_env(builder, local=False, base=builder.fn_info.callable_class)
6968
else:
70-
add_args_to_env(builder, sig, local=False, base=builder.fn_info)
69+
add_args_to_env(builder, local=False, base=builder.fn_info)
7170

7271

7372
def instantiate_env_class(builder: IRBuilder) -> Value:
@@ -92,15 +91,15 @@ def instantiate_env_class(builder: IRBuilder) -> Value:
9291
return curr_env_reg
9392

9493

95-
def load_env_registers(builder: IRBuilder, sig: FuncSignature) -> None:
94+
def load_env_registers(builder: IRBuilder) -> None:
9695
"""Load the registers for the current FuncItem being visited.
9796
9897
Adds the arguments of the FuncItem to the environment. If the
9998
FuncItem is nested inside of another function, then this also
10099
loads all of the outer environments of the FuncItem into registers
101100
so that they can be used when accessing free variables.
102101
"""
103-
add_args_to_env(builder, sig, local=True)
102+
add_args_to_env(builder, local=True)
104103

105104
fn_info = builder.fn_info
106105
fitem = fn_info.fitem
@@ -171,7 +170,6 @@ def num_bitmap_args(builder: IRBuilder, args: list[Argument]) -> int:
171170

172171
def add_args_to_env(
173172
builder: IRBuilder,
174-
sig: FuncSignature,
175173
local: bool = True,
176174
base: FuncInfo | ImplicitClass | None = None,
177175
reassign: bool = True,

mypyc/irbuild/function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,11 @@ def c() -> None:
275275
create_switch_for_generator_class(builder)
276276
add_raise_exception_blocks_to_generator_class(builder, fitem.line)
277277
else:
278-
load_env_registers(builder, sig)
278+
load_env_registers(builder)
279279
gen_arg_defaults(builder)
280280

281281
if builder.fn_info.contains_nested and not builder.fn_info.is_generator:
282-
finalize_env_class(builder, sig)
282+
finalize_env_class(builder)
283283

284284
builder.ret_types[-1] = sig.ret_type
285285

mypyc/irbuild/generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151

5252
def gen_generator_func(builder: IRBuilder, sig: FuncSignature) -> None:
5353
setup_generator_class(builder)
54-
load_env_registers(builder, sig)
54+
load_env_registers(builder)
5555
gen_arg_defaults(builder)
56-
finalize_env_class(builder, sig)
56+
finalize_env_class(builder)
5757
builder.add(Return(instantiate_generator_class(builder)))
5858

5959

@@ -340,7 +340,7 @@ def setup_env_for_generator_class(builder: IRBuilder, sig: FuncSignature) -> Non
340340

341341
# Add arguments from the original generator function to the
342342
# environment of the generator class.
343-
add_args_to_env(builder, sig, local=False, base=cls, reassign=False)
343+
add_args_to_env(builder, local=False, base=cls, reassign=False)
344344

345345
# Set the next label register for the generator class.
346346
cls.next_label_reg = builder.read(cls.next_label_target, fitem.line)

mypyc/irbuild/ll_builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,7 @@ def dunder_op(self, lreg: Value, rreg: Value | None, op: str, line: int) -> Valu
14401440

14411441
if op == "in" and method_name == "__contains__":
14421442
# contains needs to swap the r and l values
1443+
assert rreg, "'in' operator is binary and must have a valid right value"
14431444
tmp = lreg
14441445
lreg = rreg
14451446
rreg = tmp

mypyc/test-data/run-valuetype.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ class A:
246246
def __repr__(self) -> str:
247247
return f"A({self.x})"
248248

249+
def test_direct_dunders() -> None:
250+
a = A(1, 2)
251+
assert a.__hash__() == hash(1)
252+
assert a.__eq__(A(1, 2))
253+
assert not a.__eq__(A(2, 3))
254+
assert a.__len__() == 1
255+
assert a.__lt__(A(2, 3))
256+
assert a.__le__(A(2, 3))
257+
assert not a.__gt__(A(2, 3))
258+
assert not a.__ge__(A(2, 3))
259+
assert a.__contains__(1)
260+
assert not a.__contains__(2)
261+
assert a.__bool__()
262+
assert not A(0, 1).__bool__()
263+
assert a.__str__() == "A(1)"
264+
assert a.__repr__() == "A(1)"
265+
249266
def test_value_type_in_key() -> None:
250267
a = A(1, 2)
251268
d = {a: 1}

mypyc/test/test_run.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,23 @@ class TestRunStrictDunderTyping(TestRun):
413413

414414
strict_dunder_typing = True
415415
test_name_suffix = "_dunder_typing"
416-
files = ["run-dunders.test", "run-floats.test"]
416+
files = [
417+
"run-async.test",
418+
"run-bools.test",
419+
"run-bytes.test",
420+
"run-classes.test",
421+
"run-dunders.test",
422+
"run-exceptions.test",
423+
"run-floats.test",
424+
"run-functions.test",
425+
"run-generators.test",
426+
"run-i16.test",
427+
"run-i32.test",
428+
"run-i64.test",
429+
"run-integers.test",
430+
"run-lists.test",
431+
"run-traits.test",
432+
] + (["run-match.test"] if sys.version_info >= (3, 10) else [])
417433

418434

419435
def fix_native_line_number(message: str, fnam: str, delta: int) -> str:

0 commit comments

Comments
 (0)