diff --git a/my/core/__main__.py b/my/core/__main__.py index 276de26..986b05f 100644 --- a/my/core/__main__.py +++ b/my/core/__main__.py @@ -16,7 +16,7 @@ from typing import Any, Callable, Iterable, List, Optional, Sequence, Type import click -@functools.lru_cache() +@functools.lru_cache def mypy_cmd() -> Optional[Sequence[str]]: try: # preferably, use mypy from current python env @@ -43,7 +43,7 @@ def run_mypy(cfg_path: Path) -> Optional[CompletedProcess]: cmd = mypy_cmd() if cmd is None: return None - mres = run([ + mres = run([ # noqa: UP022 *cmd, '--namespace-packages', '--color-output', # not sure if works?? diff --git a/my/core/_deprecated/kompress.py b/my/core/_deprecated/kompress.py index 89e5745..803e515 100644 --- a/my/core/_deprecated/kompress.py +++ b/my/core/_deprecated/kompress.py @@ -148,14 +148,8 @@ def kexists(path: PathIsh, subpath: str) -> bool: import zipfile -if sys.version_info[:2] >= (3, 8): - # meh... zipfile.Path is not available on 3.7 - zipfile_Path = zipfile.Path -else: - if typing.TYPE_CHECKING: - zipfile_Path = Any - else: - zipfile_Path = object +# meh... zipfile.Path is not available on 3.7 +zipfile_Path = zipfile.Path @total_ordering diff --git a/my/core/query.py b/my/core/query.py index 54cd9db..bc7e222 100644 --- a/my/core/query.py +++ b/my/core/query.py @@ -707,7 +707,7 @@ def test_wrap_unsortable_with_error_and_warning() -> None: res = list(select(_mixed_iter_errors(), order_value=lambda o: isinstance(o, datetime))) 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 + returned_error = next(o for o in res if isinstance(o, Unsortable)).obj assert "Unhandled error!" == str(returned_error) diff --git a/my/core/query_range.py b/my/core/query_range.py index d077225..761b045 100644 --- a/my/core/query_range.py +++ b/my/core/query_range.py @@ -526,9 +526,8 @@ def test_parse_timedelta_string() -> None: def test_parse_datetime_float() -> None: - pnow = parse_datetime_float("now") - sec_diff = abs((pnow - datetime.now().timestamp())) + sec_diff = abs(pnow - datetime.now().timestamp()) # should probably never fail? could mock time.time # but there seems to be issues with doing that use C-libraries (as time.time) does # https://docs.python.org/3/library/unittest.mock-examples.html#partial-mocking diff --git a/my/core/stats.py b/my/core/stats.py index bfedbd2..85c2a99 100644 --- a/my/core/stats.py +++ b/my/core/stats.py @@ -414,7 +414,9 @@ def test_stat_iterable() -> None: dd = datetime.fromtimestamp(123, tz=timezone.utc) day = timedelta(days=3) - X = NamedTuple('X', [('x', int), ('d', datetime)]) + class X(NamedTuple): + x: int + d: datetime def it(): yield RuntimeError('oops!') @@ -452,9 +454,12 @@ def test_guess_datetime() -> None: dd = fromisoformat('2021-02-01T12:34:56Z') - # ugh.. https://github.com/python/mypy/issues/7281 - A = NamedTuple('A', [('x', int)]) - B = NamedTuple('B', [('x', int), ('created', datetime)]) + class A(NamedTuple): + x: int + + class B(NamedTuple): + x: int + created: datetime assert _guess_datetime(A(x=4)) is None assert _guess_datetime(B(x=4, created=dd)) == dd diff --git a/my/core/tests/denylist.py b/my/core/tests/denylist.py index 8016282..2688319 100644 --- a/my/core/tests/denylist.py +++ b/my/core/tests/denylist.py @@ -91,8 +91,7 @@ def test_denylist(tmp_path: Path) -> None: assert "59.40.113.87" not in [i.addr for i in filtered] - with open(tf, "r") as f: - data_json = json.loads(f.read()) + data_json = json.loads(tf.read_text()) assert data_json == [ { diff --git a/my/core/util.py b/my/core/util.py index 0c596fa..fdd10f9 100644 --- a/my/core/util.py +++ b/my/core/util.py @@ -12,8 +12,7 @@ from .discovery_pure import HPIModule, _is_not_module_src, has_stats, ignored def modules() -> Iterable[HPIModule]: import my - for m in _iter_all_importables(my): - yield m + yield from _iter_all_importables(my) __NOT_HPI_MODULE__ = 'Import this to mark a python file as a helper, not an actual HPI module' diff --git a/my/time/tz/via_location.py b/my/time/tz/via_location.py index 329e330..d74bdc3 100644 --- a/my/time/tz/via_location.py +++ b/my/time/tz/via_location.py @@ -218,7 +218,7 @@ def _iter_tz_depends_on() -> str: day = str(date.today()) hr = datetime.now().hour hr_truncated = hr // mod * mod - return "{}_{}".format(day, hr_truncated) + return f"{day}_{hr_truncated}" # refresh _iter_tzs every few hours -- don't think a better depends_on is possible dynamically diff --git a/ruff.toml b/ruff.toml index db926da..dda279b 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,7 +1,10 @@ +target-version = "py38" # NOTE: inferred from pyproject.toml if present + lint.extend-select = [ "F", # flakes rules -- default, but extend just in case "E", # pycodestyle -- default, but extend just in case "C4", # flake8-comprehensions -- unnecessary list/map/dict calls + "UP", # detect deprecated python stdlib stuff ] lint.ignore = [ @@ -28,4 +31,10 @@ lint.ignore = [ "F841", # Local variable `count` is assigned to but never used "F401", # imported but unused ### + +### TODO should be fine to use these with from __future__ import annotations? +### there was some issue with cachew though... double check this? + "UP006", # use type instead of Type + "UP007", # use X | Y instead of Union +### ]