Skip to content

Commit 1b80aa4

Browse files
committed
weakref: Add basic stub function to aid in porting.
1 parent f3cfc52 commit 1b80aa4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

python-stdlib/weakref/manifest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
metadata(description="Stub weakref implementation.", version="0.0.1")
2+
3+
module("weakref.py")

python-stdlib/weakref/weakref.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
# weakref
3+
https://docs.python.org/3/library/weakref.html
4+
5+
The weakref module allows the Python programmer to create weak references to objects.
6+
In the following, the term referent means the object which is referred to by a weak reference.
7+
A weak reference to an object is not enough to keep the object alive: when the only remaining references to a referent are weak references, garbage collection is free to destroy the referent and reuse its memory for something else. However, until the object is actually destroyed the weak reference may return the object even if there are no strong references to it.
8+
A primary use for weak references is to implement caches or mappings holding large objects, where it’s desired that a large object not be kept alive solely because it appears in a cache or mapping.
9+
10+
Micropython does not have support for weakref in the VM, so currently this is a simple stub
11+
module that directly assigns the object reference to simplify porting of other libraries.
12+
"""
13+
14+
15+
def ref(obj):
16+
return lambda: obj

0 commit comments

Comments
 (0)