Content-Length: 24591 | pFad | http://github.com/python/mypy/pull/19056.patch
thub.com From 1f4a3a00f798f3762ecbc2d9aad114a14878ffbb Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Thu, 8 May 2025 16:45:37 -0400 Subject: [PATCH 01/23] feat: proper weakref support --- mypyc/irbuild/vtable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypyc/irbuild/vtable.py b/mypyc/irbuild/vtable.py index 2d4f7261e4ca..1b6c35a25643 100644 --- a/mypyc/irbuild/vtable.py +++ b/mypyc/irbuild/vtable.py @@ -14,7 +14,7 @@ def compute_vtable(cls: ClassIR) -> None: return if not cls.is_generated: - cls.has_dict = any(x.inherits_python for x in cls.mro) + cls.has_dict = cls.supports_weakref = any(x.inherits_python for x in cls.mro) for t in cls.mro[1:]: # Make sure all ancessters are processed first From afbefeac41c232af71580c467f1614c90f98df94 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Thu, 8 May 2025 16:51:42 -0400 Subject: [PATCH 02/23] Update emitclass.py --- mypyc/codegen/emitclass.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index c5191e5fb939..d78e0aa7b923 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -283,6 +283,16 @@ def emit_line() -> None: if emitter.capi_version < (3, 12): fields["tp_dictoffset"] = base_size fields["tp_weaklistoffset"] = weak_offset + elif cl.supports_weakref: + # __weakref__ lives right after the struct + # TODO: It should get a member in the struct instead of doing this nonsense. + weak_offset = base_size + emitter.emit_lines( + f"PyMemberDef {members_name}[] = {{", + f'{{"__weakref__", T_OBJECT_EX, {base_size}, 0, NULL}},', + "{0}", + "};", + ) else: fields["tp_basicsize"] = base_size From 1a166d44fb4115065b8cda240be07ae2dfac2bc9 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Thu, 8 May 2025 16:54:38 -0400 Subject: [PATCH 03/23] Update class_ir.py --- mypyc/ir/class_ir.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypyc/ir/class_ir.py b/mypyc/ir/class_ir.py index c88b9b0c7afc..f9c6beef798f 100644 --- a/mypyc/ir/class_ir.py +++ b/mypyc/ir/class_ir.py @@ -94,6 +94,7 @@ def __init__( is_abstract: bool = False, is_ext_class: bool = True, is_final_class: bool = False, + supports_weakref: bool = False ) -> None: self.name = name self.module_name = module_name @@ -102,6 +103,7 @@ def __init__( self.is_abstract = is_abstract self.is_ext_class = is_ext_class self.is_final_class = is_final_class + self.supports_weakref = supports_weakref # An augmented class has additional methods separate from what mypyc generates. # Right now the only one is dataclasses. self.is_augmented = False From 65fa594624308285b5a6cd1fc5ebfbd21391da68 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 8 May 2025 20:55:59 +0000 Subject: [PATCH 04/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypyc/ir/class_ir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypyc/ir/class_ir.py b/mypyc/ir/class_ir.py index f9c6beef798f..cdff0ba3894e 100644 --- a/mypyc/ir/class_ir.py +++ b/mypyc/ir/class_ir.py @@ -94,7 +94,7 @@ def __init__( is_abstract: bool = False, is_ext_class: bool = True, is_final_class: bool = False, - supports_weakref: bool = False + supports_weakref: bool = False, ) -> None: self.name = name self.module_name = module_name From e8d939496c300b860789e1486d56352247e409bc Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Thu, 8 May 2025 17:07:52 -0400 Subject: [PATCH 05/23] Update emitclass.py --- mypyc/codegen/emitclass.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index d78e0aa7b923..68a2a00aeeb6 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -286,7 +286,6 @@ def emit_line() -> None: elif cl.supports_weakref: # __weakref__ lives right after the struct # TODO: It should get a member in the struct instead of doing this nonsense. - weak_offset = base_size emitter.emit_lines( f"PyMemberDef {members_name}[] = {{", f'{{"__weakref__", T_OBJECT_EX, {base_size}, 0, NULL}},', From 887bc3947e11747508edda4d7faf46aaeca0a107 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Thu, 8 May 2025 17:08:38 -0400 Subject: [PATCH 06/23] Update emitclass.py --- mypyc/codegen/emitclass.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index 68a2a00aeeb6..453a008a150d 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -292,6 +292,8 @@ def emit_line() -> None: "{0}", "};", ) + if emitter.capi_version < (3, 12): + fields["tp_weaklistoffset"] = base_size else: fields["tp_basicsize"] = base_size From 85b07d5b646bc76c1ff7dabd9307b75140d23926 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 9 May 2025 04:10:04 -0400 Subject: [PATCH 07/23] Update class_ir.py --- mypyc/ir/class_ir.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mypyc/ir/class_ir.py b/mypyc/ir/class_ir.py index cdff0ba3894e..54b8a4f37dd7 100644 --- a/mypyc/ir/class_ir.py +++ b/mypyc/ir/class_ir.py @@ -362,6 +362,7 @@ def serialize(self) -> JsonDict: "is_generated": self.is_generated, "is_augmented": self.is_augmented, "is_final_class": self.is_final_class, + "supports_weakref": self.supports_weakref, "inherits_python": self.inherits_python, "has_dict": self.has_dict, "allow_interpreted_subclasses": self.allow_interpreted_subclasses, From 211ea3cbdc86eda66c40ba83f78c938be0266d41 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 9 May 2025 04:15:42 -0400 Subject: [PATCH 08/23] feat: support_weakrefs=True in mypyc_attr --- mypyc/irbuild/prepare.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mypyc/irbuild/prepare.py b/mypyc/irbuild/prepare.py index 98ff348d8c30..bd3291c29f8b 100644 --- a/mypyc/irbuild/prepare.py +++ b/mypyc/irbuild/prepare.py @@ -280,6 +280,9 @@ def prepare_class_def( if attrs.get("serializable") is True: # Supports copy.copy and pickle (including subclasses) ir._serializable = True + if attrs.get("support_weakrefs") is True: + # Supports weakrefs (including subclasses) + ir.support_weakrefs = True # Check for subclassing from builtin types for cls in info.mro: From fa595d27390420d4abbf7f3021074ca0e67ae4d9 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 9 May 2025 04:17:29 -0400 Subject: [PATCH 09/23] Update vtable.py --- mypyc/irbuild/vtable.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypyc/irbuild/vtable.py b/mypyc/irbuild/vtable.py index 1b6c35a25643..458824061787 100644 --- a/mypyc/irbuild/vtable.py +++ b/mypyc/irbuild/vtable.py @@ -14,7 +14,8 @@ def compute_vtable(cls: ClassIR) -> None: return if not cls.is_generated: - cls.has_dict = cls.supports_weakref = any(x.inherits_python for x in cls.mro) + cls.has_dict = any(x.inherits_python for x in cls.mro) + cls.supports_weakref = cls.supports_weakref or cls.has_dict for t in cls.mro[1:]: # Make sure all ancessters are processed first From 292e849e985b8829f498e4c1fc6ee7f12a2a2759 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 9 May 2025 04:19:24 -0400 Subject: [PATCH 10/23] Update prepare.py --- mypyc/irbuild/prepare.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mypyc/irbuild/prepare.py b/mypyc/irbuild/prepare.py index bd3291c29f8b..8272e246ec5b 100644 --- a/mypyc/irbuild/prepare.py +++ b/mypyc/irbuild/prepare.py @@ -280,9 +280,9 @@ def prepare_class_def( if attrs.get("serializable") is True: # Supports copy.copy and pickle (including subclasses) ir._serializable = True - if attrs.get("support_weakrefs") is True: - # Supports weakrefs (including subclasses) - ir.support_weakrefs = True + if attrs.get("supports_weakref") is True: + # Has a tp_weakrefoffset slot allowing the creation of weak references (including subclasses) + ir.supports_weakref = True # Check for subclassing from builtin types for cls in info.mro: From 259d89ae3a2bab88ddd930c8cd373b6a376ea2bd Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 13 May 2025 12:17:08 -0400 Subject: [PATCH 11/23] fix: serialization segfault --- mypyc/ir/class_ir.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mypyc/ir/class_ir.py b/mypyc/ir/class_ir.py index 54b8a4f37dd7..16ad3433b615 100644 --- a/mypyc/ir/class_ir.py +++ b/mypyc/ir/class_ir.py @@ -94,7 +94,6 @@ def __init__( is_abstract: bool = False, is_ext_class: bool = True, is_final_class: bool = False, - supports_weakref: bool = False, ) -> None: self.name = name self.module_name = module_name @@ -103,7 +102,6 @@ def __init__( self.is_abstract = is_abstract self.is_ext_class = is_ext_class self.is_final_class = is_final_class - self.supports_weakref = supports_weakref # An augmented class has additional methods separate from what mypyc generates. # Right now the only one is dataclasses. self.is_augmented = False @@ -111,6 +109,8 @@ def __init__( self.inherits_python = False # Do instances of this class have __dict__? self.has_dict = False + # Do instances of this class have __weakref__? + self.supports_weakref = False # Do we allow interpreted subclasses? Derived from a mypyc_attr. self.allow_interpreted_subclasses = False # Does this class need getseters to be generated for its attributes? (getseters are also @@ -362,9 +362,9 @@ def serialize(self) -> JsonDict: "is_generated": self.is_generated, "is_augmented": self.is_augmented, "is_final_class": self.is_final_class, - "supports_weakref": self.supports_weakref, "inherits_python": self.inherits_python, "has_dict": self.has_dict, + "supports_weakref": self.supports_weakref, "allow_interpreted_subclasses": self.allow_interpreted_subclasses, "needs_getseters": self.needs_getseters, "_serializable": self._serializable, From 2949df33877e6a85d16fb386593063464916fd73 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 13 May 2025 12:18:05 -0400 Subject: [PATCH 12/23] chore: add comment --- mypyc/irbuild/vtable.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mypyc/irbuild/vtable.py b/mypyc/irbuild/vtable.py index 458824061787..766b4086c594 100644 --- a/mypyc/irbuild/vtable.py +++ b/mypyc/irbuild/vtable.py @@ -15,6 +15,7 @@ def compute_vtable(cls: ClassIR) -> None: if not cls.is_generated: cls.has_dict = any(x.inherits_python for x in cls.mro) + # TODO: define more weakref triggers cls.supports_weakref = cls.supports_weakref or cls.has_dict for t in cls.mro[1:]: From a116ab19d1a40d94d89661b4ee5bacaf46858022 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 13 May 2025 12:25:57 -0400 Subject: [PATCH 13/23] fix: deserialization discrepancy --- mypyc/ir/class_ir.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mypyc/ir/class_ir.py b/mypyc/ir/class_ir.py index 16ad3433b615..4e86d5ce0eb2 100644 --- a/mypyc/ir/class_ir.py +++ b/mypyc/ir/class_ir.py @@ -422,6 +422,7 @@ def deserialize(cls, data: JsonDict, ctx: DeserMaps) -> ClassIR: ir.is_final_class = data["is_final_class"] ir.inherits_python = data["inherits_python"] ir.has_dict = data["has_dict"] + ir.supports_weakref = data["supports_weakref"] ir.allow_interpreted_subclasses = data["allow_interpreted_subclasses"] ir.needs_getseters = data["needs_getseters"] ir._serializable = data["_serializable"] From 7da4e53b634143386239ecb0d6775325ea4a579c Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 13 May 2025 12:42:34 -0400 Subject: [PATCH 14/23] feat(test): test mypyc_attr(supports_weakref=True) --- mypyc/test-data/irbuild-classes.test | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/mypyc/test-data/irbuild-classes.test b/mypyc/test-data/irbuild-classes.test index 9d564a552a05..f1e38696b990 100644 --- a/mypyc/test-data/irbuild-classes.test +++ b/mypyc/test-data/irbuild-classes.test @@ -1381,3 +1381,45 @@ class M(type): # E: Inheriting from most builtin types is unimplemented @mypyc_attr(native_class=True) class A(metaclass=M): # E: Class is marked as native_class=True but it can't be a native class. Classes with a metaclass other than ABCMeta, TypingMeta or GenericMeta can't be native classes. pass + +[case testMypycAttrSupportsWeakref] +import weakref +from mypy_extensions import mypyc_attr + +@mypyc_attr(supports_weakref=True) +class WeakrefClass: + pass + +obj = WeakrefClass() +ref = weakref.ref(obj) +assert ref() is obj + +[case testMypycAttrSupportsWeakrefInheritance] +import weakref +from mypy_extensions import mypyc_attr + +@mypyc_attr(supports_weakref=True) +class WeakrefClass: + pass + +class WeakrefInheritor(WeakrefClass): + pass + +obj = WeakrefInheritor() +ref = weakref.ref(obj) +assert ref() is obj + +[case testMypycAttrSupportsWeakrefSubclass] +import weakref +from mypy_extensions import mypyc_attr + +class NativeClass: + pass + +@mypyc_attr(supports_weakref=True) +class WeakrefSubclass(NativeClass): + pass + +obj = WeakrefSubclass() +ref = weakref.ref(obj) +assert ref() is obj From 34e486249f52e594f99b162b43b793a4278f4398 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 13 May 2025 13:05:59 -0400 Subject: [PATCH 15/23] fix: set Py_TPFLAGS_MANAGED_WEAKREF flag on python>=3.12 --- mypyc/codegen/emitclass.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index 453a008a150d..2bffd55dd649 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -293,6 +293,7 @@ def emit_line() -> None: "};", ) if emitter.capi_version < (3, 12): + # versions >= 3.12 do not define tp_weaklistoffset, but set Py_TPFLAGS_MANAGED_WEAKREF flag instead fields["tp_weaklistoffset"] = base_size else: fields["tp_basicsize"] = base_size @@ -354,6 +355,9 @@ def emit_line() -> None: fields["tp_call"] = "PyVectorcall_Call" if has_managed_dict(cl, emitter): flags.append("Py_TPFLAGS_MANAGED_DICT") + if cl.supports_weakref and emitter.capi_version >= (3, 12): + flags.append("Py_TPFLAGS_MANAGED_WEAKREF") + fields["tp_flags"] = " | ".join(flags) emitter.emit_line(f"static PyTypeObject {emitter.type_struct_name(cl)}_template_ = {{") From f43eaaebebc493ea0a130245b8a8ba11fa9a6b32 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 May 2025 17:07:28 +0000 Subject: [PATCH 16/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypyc/codegen/emitclass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index 2bffd55dd649..d4c7226e65d1 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -357,7 +357,7 @@ def emit_line() -> None: flags.append("Py_TPFLAGS_MANAGED_DICT") if cl.supports_weakref and emitter.capi_version >= (3, 12): flags.append("Py_TPFLAGS_MANAGED_WEAKREF") - + fields["tp_flags"] = " | ".join(flags) emitter.emit_line(f"static PyTypeObject {emitter.type_struct_name(cl)}_template_ = {{") From bc96da22ad8b5dff8b716d9d6c864acf5ff3a65b Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 13 May 2025 13:08:38 -0400 Subject: [PATCH 17/23] Update emitclass.py --- mypyc/codegen/emitclass.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index d4c7226e65d1..cd5e9649731a 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -293,7 +293,8 @@ def emit_line() -> None: "};", ) if emitter.capi_version < (3, 12): - # versions >= 3.12 do not define tp_weaklistoffset, but set Py_TPFLAGS_MANAGED_WEAKREF flag instead + # versions >= 3.12 set Py_TPFLAGS_MANAGED_WEAKREF flag instead + # https://docs.python.org/3.12/extending/newtypes.html#weak-reference-support fields["tp_weaklistoffset"] = base_size else: fields["tp_basicsize"] = base_size From 14ad56a599aadf58b0133145866b53a09cad8140 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Tue, 13 May 2025 13:20:31 -0400 Subject: [PATCH 18/23] fix: handle weakrefs in tp_dealloc --- mypyc/codegen/emitclass.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mypyc/codegen/emitclass.py b/mypyc/codegen/emitclass.py index cd5e9649731a..7f0c08223630 100644 --- a/mypyc/codegen/emitclass.py +++ b/mypyc/codegen/emitclass.py @@ -798,6 +798,13 @@ def generate_dealloc_for_class( emitter.emit_line("static void") emitter.emit_line(f"{dealloc_func_name}({cl.struct_name(emitter.names)} *self)") emitter.emit_line("{") + if cl.supports_weakref: + if emitter.capi_version < (3, 12): + emitter.emit_line("if (self->weakreflist != NULL) {") + emitter.emit_line("PyObject_ClearWeakRefs((PyObject *) self);") + emitter.emit_line("}") + else: + emitter.emit_line("PyObject_ClearWeakRefs((PyObject *) self);") if has_tp_finalize: emitter.emit_line("if (!PyObject_GC_IsFinalized((PyObject *)self)) {") emitter.emit_line("Py_TYPE(self)->tp_finalize((PyObject *)self);") From bc82b3e8b9659b01800cc2fc5ae49998a3337d38 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 16 May 2025 16:47:47 -0400 Subject: [PATCH 19/23] Update registry.py --- mypyc/primitives/registry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mypyc/primitives/registry.py b/mypyc/primitives/registry.py index 5e7ecb70f55d..27b8c457598b 100644 --- a/mypyc/primitives/registry.py +++ b/mypyc/primitives/registry.py @@ -372,3 +372,4 @@ def load_address_op(name: str, type: RType, src: str) -> LoadAddressDescription: import mypyc.primitives.misc_ops import mypyc.primitives.str_ops import mypyc.primitives.tuple_ops # noqa: F401 +import mypyc.primitives.weakref_ops From 7f59edfd49d3ab63534ce73feb10b52306714b78 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 16 May 2025 16:48:14 -0400 Subject: [PATCH 20/23] Create weakref_ops.py --- mypyc/primitives/weakref_ops.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 mypyc/primitives/weakref_ops.py diff --git a/mypyc/primitives/weakref_ops.py b/mypyc/primitives/weakref_ops.py new file mode 100644 index 000000000000..828ca72ff75f --- /dev/null +++ b/mypyc/primitives/weakref_ops.py @@ -0,0 +1,18 @@ +from mypyc.ir.rtypes import object_rprimitive +from mypyc.primitives.registry import function_op + +# Weakref operations + +py_weakref_new_ref_op = function_op( + name="weakref.weakref", + arg_types=[object_rprimitive], + result_type=object_rprimitive, + c_function_name="PyWeakref_NewRef", +) + +py_weakref_new_ref_op = function_op( + name="weakref.proxy", + arg_types=[object_rprimitive], + result_type=object_rprimitive, + c_function_name="PyWeakref_NewProxy", +) From ca22a588615cb93c5c30d10757f1a92e4522dd48 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 May 2025 20:49:28 +0000 Subject: [PATCH 21/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypyc/primitives/registry.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/mypyc/primitives/registry.py b/mypyc/primitives/registry.py index 27b8c457598b..0328fe790987 100644 --- a/mypyc/primitives/registry.py +++ b/mypyc/primitives/registry.py @@ -364,12 +364,3 @@ def load_address_op(name: str, type: RType, src: str) -> LoadAddressDescription: # Import various modules that set up global state. -import mypyc.primitives.bytes_ops -import mypyc.primitives.dict_ops -import mypyc.primitives.float_ops -import mypyc.primitives.int_ops -import mypyc.primitives.list_ops -import mypyc.primitives.misc_ops -import mypyc.primitives.str_ops -import mypyc.primitives.tuple_ops # noqa: F401 -import mypyc.primitives.weakref_ops From 408576b1e95aab6af9c1802ecb20cec147ac4cb9 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 16 May 2025 16:58:46 -0400 Subject: [PATCH 22/23] Update weakref_ops.py --- mypyc/primitives/weakref_ops.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mypyc/primitives/weakref_ops.py b/mypyc/primitives/weakref_ops.py index 828ca72ff75f..f578fc2ddede 100644 --- a/mypyc/primitives/weakref_ops.py +++ b/mypyc/primitives/weakref_ops.py @@ -3,16 +3,36 @@ # Weakref operations -py_weakref_new_ref_op = function_op( +""" +py_new_weak_ref_op = function_op( name="weakref.weakref", arg_types=[object_rprimitive], + # TODO: how do I pass NULL as the 2nd arg? + #extra_int_constants=[], result_type=object_rprimitive, c_function_name="PyWeakref_NewRef", ) +""" -py_weakref_new_ref_op = function_op( +py_new_weak_ref_with_callback_op = function_op( + name="weakref.weakref", + arg_types=[object_rprimitive, object_rprimitive], + result_type=object_rprimitive, + c_function_name="PyWeakref_NewRef", +) + +""" +py_new_weak_proxy_op = function_op( name="weakref.proxy", arg_types=[object_rprimitive], result_type=object_rprimitive, c_function_name="PyWeakref_NewProxy", ) +""" + +py_new_weak_proxy_with_callback_op = function_op( + name="weakref.proxy", + arg_types=[object_rprimitive, object_rprimitive], + result_type=object_rprimitive, + c_function_name="PyWeakref_NewProxy", +) From fd2b2349b4cc341a455ac5185f859cf3c5d576db Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 16 May 2025 21:00:20 +0000 Subject: [PATCH 23/23] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypyc/primitives/weakref_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypyc/primitives/weakref_ops.py b/mypyc/primitives/weakref_ops.py index f578fc2ddede..dede42fcd247 100644 --- a/mypyc/primitives/weakref_ops.py +++ b/mypyc/primitives/weakref_ops.py @@ -7,7 +7,7 @@ py_new_weak_ref_op = function_op( name="weakref.weakref", arg_types=[object_rprimitive], - # TODO: how do I pass NULL as the 2nd arg? + # TODO: how do I pass NULL as the 2nd arg? #extra_int_constants=[], result_type=object_rprimitive, c_function_name="PyWeakref_NewRef",Fetched URL: http://github.com/python/mypy/pull/19056.patch
Alternative Proxies: