← index #14280PR #12197
Related · high · value 0.074
QUERY · ISSUE

ruff: ptr8 and ptr16 yield error on pre-commit hooks

openby ubidefeoopened 2024-04-11updated 2024-04-11
bug

Checks

  • I agree to follow the MicroPython Code of Conduct to ensure a safe and respectful space for everyone.

  • I've searched for existing issues matching this bug, and didn't find any.

Port, board and/or hardware

esp32 port, esp32s3

MicroPython version

v1.22.0-181-gca696fb65

Reproduction

Since my last check-out, a module I have been freezing for months yields an error.
I have pre-commit hooks enabled to save time on PRs, and this error never happened before with the code I had.

My module has this

@micropython.viper
    @staticmethod
    def _pack16(glyphs, idx: uint, fg_color: uint, bg_color: uint):

and inside this method

buffer = bytearray(256)
bitmap = ptr16(buffer)
glyph = ptr8(glyphs)

Expected behaviour

This check did not fail a couple of weeks ago, hence something must have changed in the checks.
Any pointers to how I should solve this?

If I add # noqa: F821 to the offending lines it passes the ruff check, but that feels wrong.

Observed behaviour

MicroPython codeformat.py for changed C files............................Passed
ruff.....................................................................Failed
- hook id: ruff
- exit code: 1

ports/esp32/boards/LILYGO_T-QT-Pro/modules/st7789py.py:633:18: F821 Undefined name `ptr16`
ports/esp32/boards/LILYGO_T-QT-Pro/modules/st7789py.py:634:17: F821 Undefined name `ptr8`
ports/esp32/boards/LILYGO_T-QT-Pro/modules/st7789py.py:664:18: F821 Undefined name `ptr16`
ports/esp32/boards/LILYGO_T-QT-Pro/modules/st7789py.py:665:17: F821 Undefined name `ptr8`
Found 4 errors.

ruff-format..............................................................Passed
Spellcheck for changed files (codespell).................................Passed

Additional Information

No, I've provided everything above.

CANDIDATE · PULL REQUEST

all: Enable ruff linter check for undefined-name (F821).

mergedby projectgusopened 2023-08-09updated 2023-08-22

If you run a linter in your editor or other part of your workflow then F821 undefined-name is excellent for quickly catching typos, missing imports, etc.

This is the sibling PR to https://github.com/micropython/micropython-lib/pull/714

The commits in this branch are code changes to enable that check. Changes include:

  • Several minor bug fixes found by this check. I don't think anything serious, but bugs all the same!
  • A couple of minor code changes (pre-setting variables) were needed for code which would have worked anyhow, but tripped the linter.
  • Added inline # ruff: noqa: F821 to files which have implicit imports (pio, asm, native module support code, etc.) Most of these are examples, so I think it's good practice to add the ignore in the file rather than globally as they may be copied and used elsewhere.
  • Globally ignore F821 in manifest files, which also have implicit imports but are generally tiny.

This PR doesn't include the other Ruff fix from #12196, so it will keep failing until rebased on that PR. (EDIT: Merged and rebased.)


This work was funded by GitHub Sponsors.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied