From 861fbf6ab5bb0c2a21a04a312453bb7adb92b8be Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 9 Aug 2023 18:14:33 +1000 Subject: [PATCH] examples: Mark asm, pio, etc. as noqa: F821 (undefined-name). These files all use decorators (@asm_thumb, @asm_pio) that add names to the function scope, that the linter cannot see. It's useful to clear them in the file not in pyproject.toml as example code will be copied and adapted elsewhere, and those developers may also use Ruff (we hope!) Signed-off-by: Angus Gratton --- examples/asmled.py | 4 ++++ examples/asmsum.py | 3 +++ examples/natmod/btree/btree_py.py | 4 ++++ examples/natmod/features2/test.py | 2 ++ examples/rp2/pio_1hz.py | 2 ++ examples/rp2/pio_exec.py | 2 ++ examples/rp2/pio_pinchange.py | 2 ++ examples/rp2/pio_pwm.py | 2 ++ examples/rp2/pio_uart_rx.py | 2 ++ examples/rp2/pio_uart_tx.py | 2 ++ examples/rp2/pio_ws2812.py | 2 ++ examples/rp2/pwm_fade.py | 2 ++ ports/qemu-arm/test-frzmpy/frozen_asm.py | 2 ++ 13 files changed, 31 insertions(+) diff --git a/examples/asmled.py b/examples/asmled.py index 09a06c184ade4..4ff35dfdf8d05 100644 --- a/examples/asmled.py +++ b/examples/asmled.py @@ -1,5 +1,9 @@ # flash LED #1 using inline assembler # this version is overly verbose and uses word stores +# +# ruff: noqa: F821 - @asm_thumb decorator adds names to function scope + + @micropython.asm_thumb def flash_led(r0): movw(r1, (stm.GPIOA + stm.GPIO_BSRRL) & 0xFFFF) diff --git a/examples/asmsum.py b/examples/asmsum.py index f2c7f285badc7..2d8c2b2c9984b 100644 --- a/examples/asmsum.py +++ b/examples/asmsum.py @@ -1,3 +1,6 @@ +# ruff: noqa: F821 - @asm_thumb decorator adds names to function scope + + @micropython.asm_thumb def asm_sum_words(r0, r1): # r0 = len diff --git a/examples/natmod/btree/btree_py.py b/examples/natmod/btree/btree_py.py index bd53c084a13be..461b045c98dfc 100644 --- a/examples/natmod/btree/btree_py.py +++ b/examples/natmod/btree/btree_py.py @@ -1,3 +1,7 @@ # Implemented in Python to support keyword arguments + +# ruff: noqa: F821 - this file is evaluated with C-defined names in scope + + def open(stream, *, flags=0, cachesize=0, pagesize=0, minkeypage=0): return _open(stream, flags, cachesize, pagesize, minkeypage) diff --git a/examples/natmod/features2/test.py b/examples/natmod/features2/test.py index 5ac80120d7338..af79b9692c216 100644 --- a/examples/natmod/features2/test.py +++ b/examples/natmod/features2/test.py @@ -1,5 +1,7 @@ # This Python code will be merged with the C code in main.c +# ruff: noqa: F821 - this file is evaluated with C-defined names in scope + import array diff --git a/examples/rp2/pio_1hz.py b/examples/rp2/pio_1hz.py index 84d761fa1434e..3ffab79d5623b 100644 --- a/examples/rp2/pio_1hz.py +++ b/examples/rp2/pio_1hz.py @@ -1,6 +1,8 @@ # Example using PIO to blink an LED and raise an IRQ at 1Hz. # Note: this does not work on Pico W because it uses Pin(25) for LED output. +# ruff: noqa: F821 - @asm_pio decorator adds names to function scope + import time from machine import Pin import rp2 diff --git a/examples/rp2/pio_exec.py b/examples/rp2/pio_exec.py index ce39f2df84306..3bea51f8dd49e 100644 --- a/examples/rp2/pio_exec.py +++ b/examples/rp2/pio_exec.py @@ -5,6 +5,8 @@ # - using set_init and set_base # - using StateMachine.exec +# ruff: noqa: F821 - @asm_pio decorator adds names to function scope + import time from machine import Pin import rp2 diff --git a/examples/rp2/pio_pinchange.py b/examples/rp2/pio_pinchange.py index 767c8e78c2eef..4a210e7f390fc 100644 --- a/examples/rp2/pio_pinchange.py +++ b/examples/rp2/pio_pinchange.py @@ -8,6 +8,8 @@ # - setting an irq handler for a StateMachine # - instantiating 2x StateMachine's with the same program and different pins +# ruff: noqa: F821 - @asm_pio decorator adds names to function scope + import time from machine import Pin import rp2 diff --git a/examples/rp2/pio_pwm.py b/examples/rp2/pio_pwm.py index 176a238091a5f..24fd6b85a3026 100644 --- a/examples/rp2/pio_pwm.py +++ b/examples/rp2/pio_pwm.py @@ -1,5 +1,7 @@ # Example of using PIO for PWM, and fading the brightness of an LED +# ruff: noqa: F821 - @asm_pio decorator adds names to function scope + from machine import Pin from rp2 import PIO, StateMachine, asm_pio from time import sleep diff --git a/examples/rp2/pio_uart_rx.py b/examples/rp2/pio_uart_rx.py index 080b6bd6392bc..f46aaa6a5e388 100644 --- a/examples/rp2/pio_uart_rx.py +++ b/examples/rp2/pio_uart_rx.py @@ -8,6 +8,8 @@ # - PIO irq handler # - using the second core via _thread +# ruff: noqa: F821 - @asm_pio decorator adds names to function scope + import _thread from machine import Pin, UART from rp2 import PIO, StateMachine, asm_pio diff --git a/examples/rp2/pio_uart_tx.py b/examples/rp2/pio_uart_tx.py index 5e4af8f6ccfdc..04abf2d0d150f 100644 --- a/examples/rp2/pio_uart_tx.py +++ b/examples/rp2/pio_uart_tx.py @@ -1,5 +1,7 @@ # Example using PIO to create a UART TX interface +# ruff: noqa: F821 - @asm_pio decorator adds names to function scope + from machine import Pin from rp2 import PIO, StateMachine, asm_pio diff --git a/examples/rp2/pio_ws2812.py b/examples/rp2/pio_ws2812.py index dd021a9d5642d..6de21ab8b7a21 100644 --- a/examples/rp2/pio_ws2812.py +++ b/examples/rp2/pio_ws2812.py @@ -1,5 +1,7 @@ # Example using PIO to drive a set of WS2812 LEDs. +# ruff: noqa: F821 - @asm_pio decorator adds names to function scope + import array, time from machine import Pin import rp2 diff --git a/examples/rp2/pwm_fade.py b/examples/rp2/pwm_fade.py index 5b7089c6b1add..6672f3443f3bd 100644 --- a/examples/rp2/pwm_fade.py +++ b/examples/rp2/pwm_fade.py @@ -1,6 +1,8 @@ # Example using PWM to fade an LED. # Note: this does not work on Pico W because it uses Pin(25) for LED output. +# ruff: noqa: F821 - @asm_pio decorator adds names to function scope + import time from machine import Pin, PWM diff --git a/ports/qemu-arm/test-frzmpy/frozen_asm.py b/ports/qemu-arm/test-frzmpy/frozen_asm.py index 2c7f5c92cd376..ba43264b389e4 100644 --- a/ports/qemu-arm/test-frzmpy/frozen_asm.py +++ b/ports/qemu-arm/test-frzmpy/frozen_asm.py @@ -1,5 +1,7 @@ # Test freezing inline-asm code. +# ruff: noqa: F821 - @asm_thumb decorator adds names to function scope + import micropython