diff --git a/my/core/query.py b/my/core/query.py index c337e5c..45806fb 100644 --- a/my/core/query.py +++ b/my/core/query.py @@ -114,7 +114,7 @@ def attribute_func(obj: T, where: Where, default: Optional[U] = None) -> Optiona if where(v): return lambda o: o.get(k, default) # type: ignore[union-attr] elif dataclasses.is_dataclass(obj): - for (field_name, _annotation) in obj.__annotations__.items(): + for field_name in obj.__annotations__.keys(): if where(getattr(obj, field_name)): return lambda o: getattr(o, field_name, default) elif is_namedtuple(obj): diff --git a/my/core/stats.py b/my/core/stats.py index aa05355..674a8d1 100644 --- a/my/core/stats.py +++ b/my/core/stats.py @@ -440,7 +440,7 @@ def _guess_datetime(x: Any) -> Optional[datetime]: d = asdict(x) except: # noqa: E722 bare except return None - for _k, v in d.items(): + for v in d.values(): if isinstance(v, datetime): return v return None diff --git a/my/polar.py b/my/polar.py index 9125f17..e52bb14 100644 --- a/my/polar.py +++ b/my/polar.py @@ -199,7 +199,7 @@ class Loader: def load_items(self, metas: Json) -> Iterable[Highlight]: - for _p, meta in metas.items(): + for _p, meta in metas.items(): # noqa: PERF102 with wrap(meta, throw=not config.defensive) as meta: yield from self.load_item(meta) diff --git a/ruff.toml b/ruff.toml index e7c6f07..2c9c39b 100644 --- a/ruff.toml +++ b/ruff.toml @@ -10,6 +10,7 @@ lint.extend-select = [ "PLR", # 'refactor' rules "B", # 'bugbear' set -- various possible bugs + "PERF", # various potential performance speedups # "FA", # TODO enable later after we make sure cachew works? # "ARG", # TODO useful, but results in some false positives in pytest fixtures... maybe later # "S", # bandit (security checks) -- tends to be not very useful, lots of nitpicks @@ -65,4 +66,12 @@ lint.ignore = [ "B010", # same as above, but setattr "B017", # pytest.raises(Exception) "B023", # seems to result in false positives? + + # a bit too annoying, offers to convert for loops to list comprehension + # , which may heart readability + "PERF401", + + # suggests no using exception in for loops + # we do use this technique a lot, plus in 3.11 happy path exception handling is "zero-cost" + "PERF203", ]