From 71fdeca5e10d99526b39d7cbd1eb8bd5aa43cbf9 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 31 Aug 2024 02:03:22 +0100 Subject: [PATCH] ci: update mypy config and make ruff config more consistent with other projects --- my/coding/github.py | 2 +- my/config.py | 2 +- my/core/__main__.py | 2 +- my/core/_deprecated/kompress.py | 2 +- my/core/tests/test_config.py | 1 - my/core/utils/concurrent.py | 2 +- my/demo.py | 1 - my/endomondo.py | 2 +- my/foursquare.py | 1 - my/hackernews/common.py | 2 +- my/jawbone/plots.py | 1 - mypy.ini | 9 ++----- ruff.toml | 43 ++++++++++++++++++--------------- 13 files changed, 32 insertions(+), 38 deletions(-) diff --git a/my/coding/github.py b/my/coding/github.py index de64f05..c495554 100644 --- a/my/coding/github.py +++ b/my/coding/github.py @@ -6,7 +6,7 @@ warnings.high('my.coding.github is deprecated! Please use my.github.all instead! # todo why aren't DeprecationWarning shown by default?? if not TYPE_CHECKING: - from ..github.all import events, get_events + from ..github.all import events, get_events # noqa: F401 # todo deprecate properly iter_events = events diff --git a/my/config.py b/my/config.py index a92b2bc..2dd9cda 100644 --- a/my/config.py +++ b/my/config.py @@ -10,7 +10,7 @@ This file is used for: - for loading the actual user config ''' #### NOTE: you won't need this line VVVV in your personal config -from my.core import init +from my.core import init # noqa: F401 ### diff --git a/my/core/__main__.py b/my/core/__main__.py index 8553942..c675676 100644 --- a/my/core/__main__.py +++ b/my/core/__main__.py @@ -577,7 +577,7 @@ def query_hpi_functions( # output == 'repl' eprint(f"\nInteract with the results by using the {click.style('res', fg='green')} variable\n") try: - import IPython # type: ignore[import] + import IPython # type: ignore[import,unused-ignore] except ModuleNotFoundError: eprint("'repl' typically uses ipython, install it with 'python3 -m pip install ipython'. falling back to stdlib...") import code diff --git a/my/core/_deprecated/kompress.py b/my/core/_deprecated/kompress.py index 63ce523..b08f04b 100644 --- a/my/core/_deprecated/kompress.py +++ b/my/core/_deprecated/kompress.py @@ -120,7 +120,7 @@ class CPath(BasePath): Path only has _accessor and _closed slots, so can't directly set .open method _accessor.open has to return file descriptor, doesn't work for compressed stuff. """ - def open(self, *args, **kwargs): + def open(self, *args, **kwargs): # noqa: ARG002 kopen_kwargs = {} mode = kwargs.get('mode') if mode is not None: diff --git a/my/core/tests/test_config.py b/my/core/tests/test_config.py index a318a95..78d1a62 100644 --- a/my/core/tests/test_config.py +++ b/my/core/tests/test_config.py @@ -8,7 +8,6 @@ from pathlib import Path import pytest import pytz -from more_itertools import ilen import my.config from my.core import notnone diff --git a/my/core/utils/concurrent.py b/my/core/utils/concurrent.py index 5f11ab0..146861b 100644 --- a/my/core/utils/concurrent.py +++ b/my/core/utils/concurrent.py @@ -47,5 +47,5 @@ class DummyExecutor(Executor): return f - def shutdown(self, wait: bool = True, **kwargs) -> None: # noqa: FBT001,FBT002 + def shutdown(self, wait: bool = True, **kwargs) -> None: # noqa: FBT001,FBT002,ARG002 self._shutdown = True diff --git a/my/demo.py b/my/demo.py index e27b5dd..0c54792 100644 --- a/my/demo.py +++ b/my/demo.py @@ -3,7 +3,6 @@ Just a demo module for testing and documentation purposes ''' import json -from abc import abstractmethod from dataclasses import dataclass from datetime import datetime, timezone, tzinfo from pathlib import Path diff --git a/my/endomondo.py b/my/endomondo.py index 1d7acc2..293a542 100644 --- a/my/endomondo.py +++ b/my/endomondo.py @@ -31,7 +31,7 @@ def inputs() -> Sequence[Path]: # todo add a doctor check for pip endoexport module import endoexport.dal as dal -from endoexport.dal import Point, Workout +from endoexport.dal import Point, Workout # noqa: F401 from .core import Res diff --git a/my/foursquare.py b/my/foursquare.py index 63e1837..394fdf3 100644 --- a/my/foursquare.py +++ b/my/foursquare.py @@ -4,7 +4,6 @@ Foursquare/Swarm checkins from datetime import datetime, timezone, timedelta from itertools import chain -from pathlib import Path import json # TODO pytz for timezone??? diff --git a/my/hackernews/common.py b/my/hackernews/common.py index 0c5ff9b..6990987 100644 --- a/my/hackernews/common.py +++ b/my/hackernews/common.py @@ -1,6 +1,6 @@ from typing import Protocol -from my.core import datetime_aware, Json +from my.core import datetime_aware def hackernews_link(id: str) -> str: diff --git a/my/jawbone/plots.py b/my/jawbone/plots.py index 5dcb63d..d26d606 100755 --- a/my/jawbone/plots.py +++ b/my/jawbone/plots.py @@ -3,7 +3,6 @@ from pathlib import Path # from kython.plotting import * from csv import DictReader -from itertools import islice from typing import Dict, Any, NamedTuple diff --git a/mypy.ini b/mypy.ini index ebc81a5..9c34fcc 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,18 +1,13 @@ [mypy] -namespace_packages = True pretty = True show_error_context = True -show_error_codes = True show_column_numbers = True show_error_end = True +warn_redundant_casts = True warn_unused_ignores = True check_untyped_defs = True -enable_error_code = possibly-undefined strict_equality = True - -# a bit annoying, it has optional ipython import which should be ignored in mypy-core configuration.. -[mypy-my.core.__main__] -warn_unused_ignores = False +enable_error_code = possibly-undefined # todo ok, maybe it wasn't such a good idea.. # mainly because then tox picks it up and running against the user config, not the repository config diff --git a/ruff.toml b/ruff.toml index 0d3bb16..5fbd657 100644 --- a/ruff.toml +++ b/ruff.toml @@ -9,6 +9,7 @@ lint.extend-select = [ "C4", # flake8-comprehensions -- unnecessary list/map/dict calls "COM", # trailing commas "EXE", # various checks wrt executable files + # "I", # sort imports "ICN", # various import conventions "FBT", # detect use of boolean arguments "FURB", # various rules @@ -23,26 +24,26 @@ lint.extend-select = [ "RET", # early returns "RUF", # various ruff-specific rules "TID", # various imports suggestions - "TCH", # various type checking rules "TRY", # various exception handling rules "UP", # detect deprecated python stdlib stuff - # "FA", # TODO enable later after we make sure cachew works? + # "FA", # suggest using from __future__ import annotations TODO enable later after we make sure cachew works? # "PTH", # pathlib migration -- TODO enable later - # "ARG", # TODO useful, but results in some false positives in pytest fixtures... maybe later - # "A", # TODO builtin shadowing -- handle later - # "S", # bandit (security checks) -- tends to be not very useful, lots of nitpicks - # "DTZ", # datetimes checks -- complaining about missing tz and mostly false positives + "ARG", # unused argument checks + # "A", # builtin shadowing -- TODO handle later # "EM", # TODO hmm could be helpful to prevent duplicate err msg in traceback.. but kinda annoying - # "FIX", # complains about fixmes/todos -- annoying - # "TD", # complains about todo formatting -- too annoying - # "ANN", # missing type annotations? seems way to string though # "ALL", # uncomment this to check for new rules! ] lint.ignore = [ - "D", # annoying nags about docstrings - "N", # pep naming + "D", # annoying nags about docstrings + "N", # pep naming + "TCH", # type checking rules, mostly just suggests moving imports under TYPE_CHECKING + "S", # bandit (security checks) -- tends to be not very useful, lots of nitpicks + "DTZ", # datetimes checks -- complaining about missing tz and mostly false positives + "FIX", # complains about fixmes/todos -- annoying + "TD", # complains about todo formatting -- too annoying + "ANN", # missing type annotations? seems way to strict though ### too opinionated style checks "E501", # too long lines @@ -62,10 +63,9 @@ lint.ignore = [ "E402", # Module level import not at top of file ### maybe consider these soon -# sometimes it's useful to give a variable a name even if we don't use it as a documentation -# on the other hand, often is a sign of error + # sometimes it's useful to give a variable a name even if we don't use it as a documentation + # on the other hand, often is a sign of error "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? @@ -90,8 +90,10 @@ lint.ignore = [ "B009", # calling gettattr with constant attribute -- this is useful to convince mypy "B010", # same as above, but setattr + "B011", # complains about assert False "B017", # pytest.raises(Exception) "B023", # seems to result in false positives? + "B028", # suggest using explicit stacklevel? TODO double check later, but not sure it's useful # complains about useless pass, but has sort of a false positive if the function has a docstring? # this is common for click entrypoints (e.g. in __main__), so disable @@ -115,7 +117,7 @@ lint.ignore = [ "PT011", # pytest raises should is too broad "PT012", # pytest raises should contain a single statement - "COM812", # trailing comma missing -- TODO maybe use this? + "COM812", # trailing comma missing -- mostly just being annoying with long multiline strings "PD901", # generic variable name df @@ -125,15 +127,12 @@ lint.ignore = [ "TRY400", # TODO double check this, might be useful "TRY401", # redundant exception in logging.exception call? TODO double check, might result in excessive logging - "TCH002", # suggests moving imports into type checking blocks -- too annoying - "TCH003", # suggests moving imports into type checking blocks -- too annoying - - "I001", # unsorted import block TODO consider these? "PGH", # TODO force error code in mypy instead - # TODO enable TID? "TID252", # Prefer absolute imports over relative imports from parent modules + "UP038", # suggests using | (union) in isisntance checks.. but it results in slower code + ## too annoying "T20", # just complains about prints and pprints "Q", # flake quotes, too annoying @@ -144,5 +143,9 @@ lint.ignore = [ "BLE001", # do not catch 'blind' Exception "INP001", # complains about implicit namespace packages "SIM", # some if statements crap + "RSE102", # complains about missing parens in exceptions ## + + "ARG001", # ugh, kinda annoying when using pytest fixtures + "F401" , # TODO nice to have, but annoying with NOT_HPI_MODULE thing ]