-
-
Notifications
You must be signed in to change notification settings - Fork 38.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better filter and documentation for qmk find #23711
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Functions for searching through QMK keyboards and keymaps. | ||
""" | ||
import contextlib | ||
import functools | ||
|
@@ -61,10 +61,22 @@ | |
|
||
class Length(FilterFunction): | ||
func_name = "length" | ||
funcMap = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a nitpick, camelCase looks off when everything else is snake_case... Its the "official" format for vars anyway. |
||
(">=", int.__ge__), | ||
("<=", int.__le__), | ||
(">", int.__gt__), | ||
("<", int.__lt__), | ||
] | ||
|
||
def apply(self, target_info: TargetInfo) -> bool: | ||
_kb, _km, info = target_info | ||
return (self.key in info and len(info[self.key]) == int(self.value)) | ||
val = int(''.join(c for c in self.value if c.isdigit())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as i can tell this is intended to convert the (potentially)
for start, func in self.funcMap: # i would also name this something like "operator"
if self.value.startswith(start):
comp = func
val = int(self.value[len(start):] # remove prefix, then convert to int (or fail trying to do so) Also, the extra parenthesis on the for, if and return look a bit off, but just code style yet again |
||
comp = int.__eq__ | ||
for (start, func) in self.funcMap: | ||
if (self.value.startswith(start)): | ||
comp = func | ||
break | ||
return (self.key in info and comp(len(info[self.key]), val)) | ||
|
||
|
||
class Contains(FilterFunction): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont like the special handling here. Imo everything should come from
filter_help
and be self-contained on the classesCould implement a
get_help()
function on the base class, as simply returning the function's name by default, and overwrite when needed. Then, for the sake of readability, print them as (instead of the current single-line approach)Where the indentation is handled by the class adding a long description and the "common" code looks like
"\n * ".join(klass.get_help() for klass in FilterFunction.__subclasses__())