Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <jim.mussared@gmail.com>
- Loading branch information
Showing
4 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -13,3 +13,6 @@ | |
base_path="..", | ||
opt=3, | ||
) | ||
|
||
# Backwards-compatible uasyncio module. | ||
module("uasyncio.py", opt=3) |
This file contains 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,8 @@ | ||
# This module just allows `import uasyncio` to work. It lazy-loads from | ||
# `asyncio` without duplicating its globals dict. | ||
|
||
|
||
def __getattr__(attr): | ||
import asyncio | ||
|
||
return getattr(asyncio, attr) |
This file contains 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,12 @@ | ||
try: | ||
import uasyncio | ||
import asyncio | ||
except ImportError: | ||
print("SKIP") | ||
raise SystemExit | ||
|
||
x = set(dir(uasyncio)) | ||
y = set(dir(asyncio)) - set(["event", "lock", "stream", "funcs"]) | ||
|
||
print(x - y) | ||
print(y - x) |
This file contains 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,2 @@ | ||
set() | ||
set() |