qmk_firmware/lib/python/qmk
Sergey Vlasov 1411c79aef
`qmk find`: Fix handling of functions in filters (#21090)
Functions in filters did not work properly except when used in the last
(or only) filter.  The problem was caused by the peculiarity of the
`lambda` behavior in Python — any variables from the outer scope are
captured only by reference, therefore any subsequent reassignment of
those variables is propagated to all lambdas created earlier in the same
scope.  Together with the laziness of `filter()` (it returns an iterator
which performs filtering on demand) this resulted in all function
filters using the values of the `key` and `value` variables which
correspond to the last filter in the sequence, therefore the result of
filtering was wrong if some filter with a function was not the last one
in the sequence.

Apparently the shortest way to make a Python lambda capture some
variables by value is to add arguments with default values for such
variables (default values are evaluated when the lambda is created, and
any subsequent reassignments in the outer scope no longer changes them).
This makes filters with functions work properly even when such filters
are not at the last position in the sequence.
2023-05-30 19:24:19 +01:00
..
cli Fix up `qmk find` when not specifying filters. (#21059) 2023-05-27 13:23:07 +10:00
tests Update json2c to use dump_lines (#21013) 2023-05-22 07:03:59 +01:00
__init__.py
c_parse.py
commands.py Append user variables to the end of make command (#20177) 2023-04-03 15:20:39 +10:00
comment_remover.py
constants.py
converter.py
datetime.py
decorators.py
errors.py
flashers.py
git.py
importers.py `qmk format-json`: Expose full key path and respect `sort_keys` (#20836) 2023-05-20 22:15:05 +10:00
info.py `qmk info`: account for ISO enter when calculating layout X offset (#20325) 2023-04-04 01:15:35 +01:00
json_encoders.py `qmk format-json`: Expose full key path and respect `sort_keys` (#20836) 2023-05-20 22:15:05 +10:00
json_schema.py
keyboard.py
keycodes.py
keymap.py CLI: Improve keymap folder resolution (#20981) 2023-05-19 16:05:43 +10:00
makefile.py `qmk find`: usability improvements (#20440) 2023-05-20 22:14:43 +10:00
math.py
painter.py [Bugfix + Refactor] `qmk painter-convert-graphics` (#19994) 2023-05-26 03:07:06 +01:00
painter_qff.py
painter_qgf.py
path.py CLI: Improve keymap folder resolution (#20981) 2023-05-19 16:05:43 +10:00
search.py `qmk find`: Fix handling of functions in filters (#21090) 2023-05-30 19:24:19 +01:00
submodules.py