ruff: enable and fix C4 ruleset

This commit is contained in:
Dima Gerasimov 2024-08-27 22:50:37 +01:00 committed by karlicoss
parent c08ddbc781
commit d244c7cc4e
19 changed files with 48 additions and 38 deletions

View file

@ -244,7 +244,7 @@ class ZipPath(zipfile_Path):
# see https://en.wikipedia.org/wiki/ZIP_(file_format)#Structure
dt = datetime(*self.root.getinfo(self.at).date_time)
ts = int(dt.timestamp())
params = dict(
params = dict( # noqa: C408
st_mode=0,
st_ino=0,
st_dev=0,

View file

@ -80,7 +80,7 @@ def get_files(
paths.append(src)
if sort:
paths = list(sorted(paths))
paths = sorted(paths)
if len(paths) == 0:
# todo make it conditionally defensive based on some global settings

View file

@ -60,8 +60,10 @@ class _A:
def test_freezer() -> None:
val = _A(x=dict(an_int=123, an_any=[1, 2, 3]))
val = _A(x={
'an_int': 123,
'an_any': [1, 2, 3],
})
af = Freezer(_A)
fval = af.freeze(val)

View file

@ -72,16 +72,16 @@ def fill(it: Iterable[Any], *, measurement: str, reset: bool=RESET_DEFAULT, dt_c
fields = filter_dict(d)
yield dict(
measurement=measurement,
yield {
'measurement': measurement,
# TODO maybe good idea to tag with database file/name? to inspect inconsistencies etc..
# hmm, so tags are autoindexed and might be faster?
# not sure what's the big difference though
# "fields are data and tags are metadata"
tags=tags,
time=dt,
fields=fields,
)
'tags': tags,
'time': dt,
'fields': fields,
}
from more_itertools import chunked
# "The optimal batch size is 5000 lines of line protocol."

View file

@ -222,7 +222,7 @@ def test_as_dataframe() -> None:
from .compat import fromisoformat
it = (dict(i=i, s=f'str{i}') for i in range(5))
it = ({'i': i, 's': f'str{i}'} for i in range(5))
with pytest.warns(UserWarning, match=r"No 'error' column") as record_warnings: # noqa: F841
df: DataFrameT = as_dataframe(it)
# todo test other error col policies

View file

@ -655,7 +655,7 @@ def test_wrap_unsortable() -> None:
# by default, wrap unsortable
res = list(select(_mixed_iter(), order_key="z"))
assert Counter(map(lambda t: type(t).__name__, res)) == Counter({"_A": 4, "Unsortable": 2})
assert Counter(type(t).__name__ for t in res) == Counter({"_A": 4, "Unsortable": 2})
def test_disabled_wrap_unsorted() -> None:
@ -674,7 +674,7 @@ def test_drop_unsorted() -> None:
# test drop unsortable, should remove them before the 'sorted' call
res = list(select(_mixed_iter(), order_key="z", wrap_unsorted=False, drop_unsorted=True))
assert len(res) == 4
assert Counter(map(lambda t: type(t).__name__, res)) == Counter({"_A": 4})
assert Counter(type(t).__name__ for t in res) == Counter({"_A": 4})
def test_drop_exceptions() -> None:
@ -705,7 +705,7 @@ def test_wrap_unsortable_with_error_and_warning() -> None:
# by default should wrap unsortable (error)
with pytest.warns(UserWarning, match=r"encountered exception"):
res = list(select(_mixed_iter_errors(), order_value=lambda o: isinstance(o, datetime)))
assert Counter(map(lambda t: type(t).__name__, res)) == Counter({"_A": 4, "_B": 2, "Unsortable": 1})
assert Counter(type(t).__name__ for t in res) == Counter({"_A": 4, "_B": 2, "Unsortable": 1})
# compare the returned error wrapped in the Unsortable
returned_error = next((o for o in res if isinstance(o, Unsortable))).obj
assert "Unhandled error!" == str(returned_error)
@ -717,7 +717,7 @@ def test_order_key_unsortable() -> None:
# both unsortable and items which dont match the order_by (order_key) in this case should be classified unsorted
res = list(select(_mixed_iter_errors(), order_key="z"))
assert Counter(map(lambda t: type(t).__name__, res)) == Counter({"_A": 4, "Unsortable": 3})
assert Counter(type(t).__name__ for t in res) == Counter({"_A": 4, "Unsortable": 3})
def test_order_default_param() -> None:
@ -737,7 +737,7 @@ def test_no_recursive_unsortables() -> None:
# select to select as input, wrapping unsortables the first time, second should drop them
# reverse=True to send errors to the end, so the below order_key works
res = list(select(_mixed_iter_errors(), order_key="z", reverse=True))
assert Counter(map(lambda t: type(t).__name__, res)) == Counter({"_A": 4, "Unsortable": 3})
assert Counter(type(t).__name__ for t in res) == Counter({"_A": 4, "Unsortable": 3})
# drop_unsorted
dropped = list(select(res, order_key="z", drop_unsorted=True))

View file

@ -35,7 +35,7 @@ SqliteRowFactory = Callable[[sqlite3.Cursor, sqlite3.Row], Any]
def dict_factory(cursor, row):
fields = [column[0] for column in cursor.description]
return {key: value for key, value in zip(fields, row)}
return dict(zip(fields, row))
Factory = Union[SqliteRowFactory, Literal['row', 'dict']]