From b2fd506d86b695e8f8745b552cbee78e37e4b432 Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Thu, 4 Sep 2025 10:19:12 -0400 Subject: [PATCH 1/3] Check functions without annotations in mypyc tests --- mypyc/test-data/fixtures/ir.py | 1 + mypyc/test-data/run-classes.test | 8 ++++---- mypyc/test-data/run-singledispatch.test | 21 +++++++++++---------- mypyc/test-data/run-weakref.test | 13 ++++--------- mypyc/test/test_run.py | 1 + 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/mypyc/test-data/fixtures/ir.py b/mypyc/test-data/fixtures/ir.py index c041c661741c..ecca7346f036 100644 --- a/mypyc/test-data/fixtures/ir.py +++ b/mypyc/test-data/fixtures/ir.py @@ -47,6 +47,7 @@ def __ne__(self, x: object) -> bool: pass class type: def __init__(self, o: object) -> None: ... def __or__(self, o: object) -> Any: ... + def __new__(cls, *args: object) -> Any: ... __name__ : str __annotations__: Dict[str, Any] diff --git a/mypyc/test-data/run-classes.test b/mypyc/test-data/run-classes.test index 6f1217bd36e6..49bd8ad1e6ab 100644 --- a/mypyc/test-data/run-classes.test +++ b/mypyc/test-data/run-classes.test @@ -811,7 +811,7 @@ def test_classmethod_with_allow_interpreted() -> None: [file interp.py] def make_interpreted_subclass(base): - class Sub(base): + class Sub(base): # type: ignore @classmethod def g(cls, x: int) -> int: return x + 3 @@ -2473,7 +2473,7 @@ def test_interpreted_subclass() -> None: from testutil import assertRaises def define_interpreted_subclass(b): - class DerivedInterpreted1(b): + class DerivedInterpreted1(b): # type: ignore def __init__(self): # Don't call base class __init__ pass @@ -2486,10 +2486,10 @@ def define_interpreted_subclass(b): with assertRaises(AttributeError): del d1.x - class DerivedInterpreted1(b): + class DerivedInterpreted2(b): # type: ignore def __init__(self): super().__init__('y') - d2 = DerivedInterpreted1() + d2 = DerivedInterpreted2() assert d2.x == 5 assert d2.s == 'y' with assertRaises(AttributeError): diff --git a/mypyc/test-data/run-singledispatch.test b/mypyc/test-data/run-singledispatch.test index a119c325984a..ced93a91639b 100644 --- a/mypyc/test-data/run-singledispatch.test +++ b/mypyc/test-data/run-singledispatch.test @@ -286,16 +286,17 @@ def build(n: int) -> Tree: return Leaf() return Node(n, build(n - 1), build(n - 1)) -def test_sum_and_equal(): - tree = build(5) - tree2 = build(5) - tree2.right.right.right.value = 10 - assert calc_sum(tree) == 57 - assert calc_sum(tree2) == 65 - assert equal(tree, tree) - assert not equal(tree, tree2) - tree3 = build(4) - assert not equal(tree, tree3) +[file driver.py] +from native import build, calc_sum, equal +tree = build(5) +tree2 = build(5) +tree2.right.right.right.value = 10 +assert calc_sum(tree) == 57 +assert calc_sum(tree2) == 65 +assert equal(tree, tree) +assert not equal(tree, tree2) +tree3 = build(4) +assert not equal(tree, tree3) [case testSimulateMypySingledispatch] from functools import singledispatch diff --git a/mypyc/test-data/run-weakref.test b/mypyc/test-data/run-weakref.test index 902c9e407ff4..d344f3364bbe 100644 --- a/mypyc/test-data/run-weakref.test +++ b/mypyc/test-data/run-weakref.test @@ -1,6 +1,7 @@ # Test cases for weakrefs (compile and run) -[case testWeakrefRef] +# TODO: fixme +[case testWeakrefRef-xfail] from weakref import ref from mypy_extensions import mypyc_attr @@ -9,22 +10,16 @@ class Object: """some random weakreffable object""" pass -def test_weakref_ref(): +def test_weakref_ref() -> None: obj = Object() r = ref(obj) assert r() is obj obj = None assert r() is None, r() -def test_weakref_ref_with_callback(): +def test_weakref_ref_with_callback() -> None: obj = Object() r = ref(obj, lambda x: x) assert r() is obj obj = None assert r() is None, r() - -[file driver.py] -from native import test_weakref_ref, test_weakref_ref_with_callback - -test_weakref_ref() -test_weakref_ref_with_callback() diff --git a/mypyc/test/test_run.py b/mypyc/test/test_run.py index 172a1016dd91..b55847785e25 100644 --- a/mypyc/test/test_run.py +++ b/mypyc/test/test_run.py @@ -204,6 +204,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) -> options.preserve_asts = True options.allow_empty_bodies = True options.incremental = self.separate + options.check_untyped_defs = True # Avoid checking modules/packages named 'unchecked', to provide a way # to test interacting with code we don't have types for. From b44e3be1c8710ef4ea35ea8baed425d858a44021 Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Fri, 5 Sep 2025 08:50:19 -0400 Subject: [PATCH 2/3] feedback --- mypyc/test-data/run-classes.test | 6 +++--- mypyc/test-data/run-singledispatch.test | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/mypyc/test-data/run-classes.test b/mypyc/test-data/run-classes.test index 49bd8ad1e6ab..1f2466179e6d 100644 --- a/mypyc/test-data/run-classes.test +++ b/mypyc/test-data/run-classes.test @@ -811,7 +811,7 @@ def test_classmethod_with_allow_interpreted() -> None: [file interp.py] def make_interpreted_subclass(base): - class Sub(base): # type: ignore + class Sub(base): # type: ignore[misc, valid-type] @classmethod def g(cls, x: int) -> int: return x + 3 @@ -2473,7 +2473,7 @@ def test_interpreted_subclass() -> None: from testutil import assertRaises def define_interpreted_subclass(b): - class DerivedInterpreted1(b): # type: ignore + class DerivedInterpreted1(b): # type: ignore[misc, valid-type] def __init__(self): # Don't call base class __init__ pass @@ -2486,7 +2486,7 @@ def define_interpreted_subclass(b): with assertRaises(AttributeError): del d1.x - class DerivedInterpreted2(b): # type: ignore + class DerivedInterpreted2(b): # type: ignore[misc, valid-type] def __init__(self): super().__init__('y') d2 = DerivedInterpreted2() diff --git a/mypyc/test-data/run-singledispatch.test b/mypyc/test-data/run-singledispatch.test index ced93a91639b..a119c325984a 100644 --- a/mypyc/test-data/run-singledispatch.test +++ b/mypyc/test-data/run-singledispatch.test @@ -286,17 +286,16 @@ def build(n: int) -> Tree: return Leaf() return Node(n, build(n - 1), build(n - 1)) -[file driver.py] -from native import build, calc_sum, equal -tree = build(5) -tree2 = build(5) -tree2.right.right.right.value = 10 -assert calc_sum(tree) == 57 -assert calc_sum(tree2) == 65 -assert equal(tree, tree) -assert not equal(tree, tree2) -tree3 = build(4) -assert not equal(tree, tree3) +def test_sum_and_equal(): + tree = build(5) + tree2 = build(5) + tree2.right.right.right.value = 10 + assert calc_sum(tree) == 57 + assert calc_sum(tree2) == 65 + assert equal(tree, tree) + assert not equal(tree, tree2) + tree3 = build(4) + assert not equal(tree, tree3) [case testSimulateMypySingledispatch] from functools import singledispatch From 7997d5d1211f3afd6fcd6bf07aa5ddf478be995c Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Fri, 5 Sep 2025 11:18:56 -0400 Subject: [PATCH 3/3] restore run-weakref.test --- mypyc/test-data/run-weakref.test | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mypyc/test-data/run-weakref.test b/mypyc/test-data/run-weakref.test index d344f3364bbe..902c9e407ff4 100644 --- a/mypyc/test-data/run-weakref.test +++ b/mypyc/test-data/run-weakref.test @@ -1,7 +1,6 @@ # Test cases for weakrefs (compile and run) -# TODO: fixme -[case testWeakrefRef-xfail] +[case testWeakrefRef] from weakref import ref from mypy_extensions import mypyc_attr @@ -10,16 +9,22 @@ class Object: """some random weakreffable object""" pass -def test_weakref_ref() -> None: +def test_weakref_ref(): obj = Object() r = ref(obj) assert r() is obj obj = None assert r() is None, r() -def test_weakref_ref_with_callback() -> None: +def test_weakref_ref_with_callback(): obj = Object() r = ref(obj, lambda x: x) assert r() is obj obj = None assert r() is None, r() + +[file driver.py] +from native import test_weakref_ref, test_weakref_ref_with_callback + +test_weakref_ref() +test_weakref_ref_with_callback()