ruff: enable PERF checks set
This commit is contained in:
parent
985c0f94e6
commit
bd1e5d2f11
4 changed files with 12 additions and 3 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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",
|
||||
]
|
||||
|
|
Loading…
Add table
Reference in a new issue