Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3k
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:masterChoose a base branch fromBobTheBuidler:weakref-call
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Draft
Changes from1 commit
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
6b28f17
feat: new primitive for weakref.ref
BobTheBuidler8d41c26
fix(test): fix test ref
BobTheBuidler97f9186
fix(test): only test with callback
BobTheBuidler81eadfb
Update run-weakref.test
BobTheBuidler3b71a7f
feat: new primitive for `weakref.__call__`
BobTheBuidler3a1662d
Merge branch 'master' into weakref-call
BobTheBuidlerac503a3
Update weakref_ops.py
BobTheBuidlerc96f949
Update rtypes.py
BobTheBuidlera25eab6
Update weakref_ops.py
BobTheBuidlere50b118
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot]28f00e5
Merge branch 'master' into weakref-call
BobTheBuidlerf5c4cc8
Update irbuild-weakref.test
BobTheBuidlerFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
feat: new primitive for weakref.ref
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commit6b28f17a59a7160eeaf73cdc7ffddf979a3083ce
There are no files selected for viewing
3 changes: 2 additions & 1 deletionmypyc/primitives/registry.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletionsmypyc/primitives/weakref_ops.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from mypyc.ir.ops import ERR_MAGIC | ||
from mypyc.ir.rtypes import object_rprimitive | ||
from mypyc.primitives.registry import function_op | ||
# Weakref operations | ||
new_ref_op = function_op( | ||
name="weakref.ReferenceType", | ||
arg_types=[object_rprimitive, object_rprimitive], | ||
return_type=object_rprimitive, | ||
c_function_name="PyWeakref_NewRef", | ||
error_kind=ERR_MAGIC, | ||
) |
51 changes: 51 additions & 0 deletionsmypyc/test-data/irbuild-weakref.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[case testWeakrefRef] | ||
import weakref | ||
from typing import Any, Callable | ||
def f(x: object) -> object: | ||
return weakref.ref(x) | ||
[out] | ||
def f(x): | ||
x, r0 :: object | ||
L0: | ||
r0 = PyWeakref_NewRef(x, NULL) | ||
return r0 | ||
[case testWeakrefRefCallback] | ||
import weakref | ||
from typing import Any, Callable | ||
def f(x: object, cb: Callable[[object], Any]) -> object: | ||
return weakref.ref(x, cb) | ||
[out] | ||
def f(x, cb): | ||
x, cb, r0 :: object | ||
L0: | ||
r0 = PyWeakref_NewRef(x, cb) | ||
return r0 | ||
[case testFromWeakrefRef] | ||
from typing import Any, Callable | ||
from weakref import ref | ||
def f(x: object) -> object: | ||
return ref(x) | ||
[out] | ||
def f(x): | ||
x, r0 :: object | ||
L0: | ||
r0 = PyWeakref_NewRef(x, NULL) | ||
return r0 | ||
[case testFromWeakrefRefCallback] | ||
from typing import Any, Callable | ||
from weakref import ref | ||
def f(x: object, cb: Callable[[object], Any]) -> object: | ||
return ref(x, cb) | ||
[out] | ||
def f(x, cb): | ||
x, cb, r0 :: object | ||
L0: | ||
r0 = PyWeakref_NewRef(x, cb) | ||
return r0 |
22 changes: 22 additions & 0 deletionsmypyc/test-data/run-weakref.test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Test cases for weakrefs (compile and run) | ||
[case testWeakrefRef] | ||
import asyncio | ||
import pytest # type: ignore [import-not-found] | ||
from weakref import ref | ||
def test_weakref_ref(): | ||
# some random weakreffable object | ||
obj = asyncio.new_event_loop() | ||
r = ref(obj) | ||
assert r() is obj | ||
obj = None | ||
assert r() is None, r() | ||
def test_weakref_ref_with_callback(): | ||
# some random weakreffable object | ||
obj = asyncio.new_event_loop() | ||
r = ref(obj, lambda x: x) | ||
assert r() is obj | ||
obj = None | ||
assert r() is None, r() |
1 change: 1 addition & 0 deletionsmypyc/test/test_irbuild.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsmypyc/test/test_run.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.