Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WIP: new mypyc primitive forweakref.ref.__call__#19145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
BobTheBuidler wants to merge12 commits intopython:master
base:master
Choose a base branch
Loading
fromBobTheBuidler:weakref-call
Draft
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
feat: new primitive forweakref.__call__
  • Loading branch information
@BobTheBuidler
BobTheBuidler committedMay 23, 2025
commit3b71a7f71d1ede3ff858285c68d9cce43fa02ed0
10 changes: 9 additions & 1 deletionmypyc/primitives/weakref_ops.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
from mypyc.ir.ops import ERR_MAGIC
from mypyc.ir.rtypes import object_rprimitive
from mypyc.primitives.registry import function_op
from mypyc.primitives.registry importERR_NEG_INT,function_op

# Weakref operations

Expand All@@ -11,3 +11,11 @@
c_function_name="PyWeakref_NewRef",
error_kind=ERR_MAGIC,
)

deref_op = function_op(
name="weakref.ReferenceType.__call__",
arg_types=[object_rprimitive],
return_type=object_rprimitive,
c_function_name="PyWeakref_GetRef",
error_kind=ERR_NEG_INT,
)
14 changes: 8 additions & 6 deletionsmypyc/test-data/irbuild-weakref.test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,24 +2,26 @@
import weakref
from typing import Any, Callable
def f(x: object, cb: Callable[[object], Any]) -> object:
return weakref.ref(x, cb)
return weakref.ref(x, cb)()

[out]
def f(x, cb):
x, cb, r0 :: object
x, cb, r0, r1 :: object
L0:
r0 = PyWeakref_NewRef(x, cb)
return r0
r1 = PyWeakref_GetRef(r0)
return r1

[case testFromWeakrefRefCallback]
from typing import Any, Callable
from weakref import ref
def f(x: object, cb: Callable[[object], Any]) -> object:
return ref(x, cb)
return ref(x, cb)()

[out]
def f(x, cb):
x, cb, r0 :: object
x, cb, r0, r1 :: object
L0:
r0 = PyWeakref_NewRef(x, cb)
return r0
r1 = PyWeakref_GetRef(r0)
return r1
Loading

[8]ページ先頭

©2009-2025 Movatter.jp