add annotations to __future__; don't generate __future__ stubs

This commit is contained in:
Dan Halbert 2022-03-07 17:43:15 -05:00
parent f59f8acf78
commit c70425ab6b
2 changed files with 14 additions and 2 deletions

View File

@ -36,6 +36,13 @@
//| The `__future__` module is used by other Python implementations to
//| enable forward compatibility for features enabled by default in an upcoming version.
//| """
//|
//| annotations: Any
//| """In CPython, ``from __future import annotations``
//| indicates that evaluation of annotations is postponed, as described in PEP 563.
//| CircuitPython (and MicroPython) ignore annotations entirely, whether or not this feature is imported.
//| This is a limitation of CircuitPython and MicroPython for efficiency reasons.
//| """
STATIC const mp_rom_map_elem_t future_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR___future__) },

View File

@ -16,7 +16,9 @@ import isort
import black
IMPORTS_IGNORE = frozenset(
PATHS_IGNORE = frozenset({"shared-bindings/__future__"})
TYPE_MODULE_IMPORTS_IGNORE = frozenset(
{
"int",
"float",
@ -125,7 +127,7 @@ def extract_imports(tree):
return
for node in ast.walk(anno_tree):
if isinstance(node, ast.Name):
if node.id in IMPORTS_IGNORE:
if node.id in TYPE_MODULE_IMPORTS_IGNORE:
continue
elif node.id in IMPORTS_TYPING:
typing.add(node.id)
@ -174,6 +176,9 @@ def convert_folder(top_level, stub_directory):
for filename in filenames:
full_path = os.path.join(top_level, filename)
if full_path in PATHS_IGNORE:
continue
file_lines = []
if os.path.isdir(full_path):
(mok, mtotal) = convert_folder(full_path, os.path.join(stub_directory, filename))