tools/gen-cpydiff: uimports: Replace only imports, not arbitrary substrings.
Previously, code just unconditionally replaced any substring in the source,
e.g. it would replace "bytearray" with "byteuarray". Make it replace
"import array" with "import uarray as array".
@@ -83,7 +83,7 @@ def uimports(code):
""" converts CPython module names into MicroPython equivalents """
for uimport in UIMPORTLIST:
uimport = bytes(uimport, 'utf8')
- code = code.replace(uimport, b'u' + uimport)
+ code = code.replace(b'import ' + uimport, b'import u' + uimport + b' as ' + uimport)
return code
