Skip to content

Commit ca79b49

Browse files
jimmodpgeorge
authored andcommitted
extmod/asyncio/uasyncio.py: Add backwards-compatible uasyncio alias.
This allows existing code that does `import uasyncio` or `import uasyncio as asyncio` to continue working. It uses the same lazy-loading as asyncio to prevent loading of unused features. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
1 parent 7979a4d commit ca79b49

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

extmod/asyncio/manifest.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
base_path="..",
1414
opt=3,
1515
)
16+
17+
# Backwards-compatible uasyncio module.
18+
module("uasyncio.py", opt=3)

extmod/asyncio/uasyncio.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This module just allows `import uasyncio` to work. It lazy-loads from
2+
# `asyncio` without duplicating its globals dict.
3+
4+
5+
def __getattr__(attr):
6+
import asyncio
7+
8+
return getattr(asyncio, attr)

tests/extmod/asyncio_as_uasyncio.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
try:
2+
import uasyncio
3+
import asyncio
4+
except ImportError:
5+
print("SKIP")
6+
raise SystemExit
7+
8+
x = set(dir(uasyncio))
9+
y = set(dir(asyncio)) - set(["event", "lock", "stream", "funcs"])
10+
11+
print(x - y)
12+
print(y - x)
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set()
2+
set()

0 commit comments

Comments
 (0)