ci: update mypy config and make ruff config more consistent with other projects

This commit is contained in:
Dima Gerasimov 2024-08-31 02:03:22 +01:00 committed by karlicoss
parent d58453410c
commit 71fdeca5e1
13 changed files with 32 additions and 38 deletions

View file

@ -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?? # todo why aren't DeprecationWarning shown by default??
if not TYPE_CHECKING: if not TYPE_CHECKING:
from ..github.all import events, get_events from ..github.all import events, get_events # noqa: F401
# todo deprecate properly # todo deprecate properly
iter_events = events iter_events = events

View file

@ -10,7 +10,7 @@ This file is used for:
- for loading the actual user config - for loading the actual user config
''' '''
#### NOTE: you won't need this line VVVV in your personal 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
### ###

View file

@ -577,7 +577,7 @@ def query_hpi_functions(
# output == 'repl' # output == 'repl'
eprint(f"\nInteract with the results by using the {click.style('res', fg='green')} variable\n") eprint(f"\nInteract with the results by using the {click.style('res', fg='green')} variable\n")
try: try:
import IPython # type: ignore[import] import IPython # type: ignore[import,unused-ignore]
except ModuleNotFoundError: except ModuleNotFoundError:
eprint("'repl' typically uses ipython, install it with 'python3 -m pip install ipython'. falling back to stdlib...") eprint("'repl' typically uses ipython, install it with 'python3 -m pip install ipython'. falling back to stdlib...")
import code import code

View file

@ -120,7 +120,7 @@ class CPath(BasePath):
Path only has _accessor and _closed slots, so can't directly set .open method 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. _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 = {} kopen_kwargs = {}
mode = kwargs.get('mode') mode = kwargs.get('mode')
if mode is not None: if mode is not None:

View file

@ -8,7 +8,6 @@ from pathlib import Path
import pytest import pytest
import pytz import pytz
from more_itertools import ilen
import my.config import my.config
from my.core import notnone from my.core import notnone

View file

@ -47,5 +47,5 @@ class DummyExecutor(Executor):
return f 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 self._shutdown = True

View file

@ -3,7 +3,6 @@ Just a demo module for testing and documentation purposes
''' '''
import json import json
from abc import abstractmethod
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime, timezone, tzinfo from datetime import datetime, timezone, tzinfo
from pathlib import Path from pathlib import Path

View file

@ -31,7 +31,7 @@ def inputs() -> Sequence[Path]:
# todo add a doctor check for pip endoexport module # todo add a doctor check for pip endoexport module
import endoexport.dal as dal import endoexport.dal as dal
from endoexport.dal import Point, Workout from endoexport.dal import Point, Workout # noqa: F401
from .core import Res from .core import Res

View file

@ -4,7 +4,6 @@ Foursquare/Swarm checkins
from datetime import datetime, timezone, timedelta from datetime import datetime, timezone, timedelta
from itertools import chain from itertools import chain
from pathlib import Path
import json import json
# TODO pytz for timezone??? # TODO pytz for timezone???

View file

@ -1,6 +1,6 @@
from typing import Protocol from typing import Protocol
from my.core import datetime_aware, Json from my.core import datetime_aware
def hackernews_link(id: str) -> str: def hackernews_link(id: str) -> str:

View file

@ -3,7 +3,6 @@
from pathlib import Path from pathlib import Path
# from kython.plotting import * # from kython.plotting import *
from csv import DictReader from csv import DictReader
from itertools import islice
from typing import Dict, Any, NamedTuple from typing import Dict, Any, NamedTuple

View file

@ -1,18 +1,13 @@
[mypy] [mypy]
namespace_packages = True
pretty = True pretty = True
show_error_context = True show_error_context = True
show_error_codes = True
show_column_numbers = True show_column_numbers = True
show_error_end = True show_error_end = True
warn_redundant_casts = True
warn_unused_ignores = True warn_unused_ignores = True
check_untyped_defs = True check_untyped_defs = True
enable_error_code = possibly-undefined
strict_equality = True strict_equality = True
enable_error_code = possibly-undefined
# a bit annoying, it has optional ipython import which should be ignored in mypy-core configuration..
[mypy-my.core.__main__]
warn_unused_ignores = False
# todo ok, maybe it wasn't such a good idea.. # 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 # mainly because then tox picks it up and running against the user config, not the repository config

View file

@ -9,6 +9,7 @@ lint.extend-select = [
"C4", # flake8-comprehensions -- unnecessary list/map/dict calls "C4", # flake8-comprehensions -- unnecessary list/map/dict calls
"COM", # trailing commas "COM", # trailing commas
"EXE", # various checks wrt executable files "EXE", # various checks wrt executable files
# "I", # sort imports
"ICN", # various import conventions "ICN", # various import conventions
"FBT", # detect use of boolean arguments "FBT", # detect use of boolean arguments
"FURB", # various rules "FURB", # various rules
@ -23,19 +24,13 @@ lint.extend-select = [
"RET", # early returns "RET", # early returns
"RUF", # various ruff-specific rules "RUF", # various ruff-specific rules
"TID", # various imports suggestions "TID", # various imports suggestions
"TCH", # various type checking rules
"TRY", # various exception handling rules "TRY", # various exception handling rules
"UP", # detect deprecated python stdlib stuff "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 # "PTH", # pathlib migration -- TODO enable later
# "ARG", # TODO useful, but results in some false positives in pytest fixtures... maybe later "ARG", # unused argument checks
# "A", # TODO builtin shadowing -- handle later # "A", # builtin shadowing -- TODO 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
# "EM", # TODO hmm could be helpful to prevent duplicate err msg in traceback.. but kinda annoying # "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! # "ALL", # uncomment this to check for new rules!
] ]
@ -43,6 +38,12 @@ lint.extend-select = [
lint.ignore = [ lint.ignore = [
"D", # annoying nags about docstrings "D", # annoying nags about docstrings
"N", # pep naming "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 ### too opinionated style checks
"E501", # too long lines "E501", # too long lines
@ -62,10 +63,9 @@ lint.ignore = [
"E402", # Module level import not at top of file "E402", # Module level import not at top of file
### maybe consider these soon ### maybe consider these soon
# sometimes it's useful to give a variable a name even if we don't use it as a documentation # 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 # on the other hand, often is a sign of error
"F841", # Local variable `count` is assigned to but never used "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? ### 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 "B009", # calling gettattr with constant attribute -- this is useful to convince mypy
"B010", # same as above, but setattr "B010", # same as above, but setattr
"B011", # complains about assert False
"B017", # pytest.raises(Exception) "B017", # pytest.raises(Exception)
"B023", # seems to result in false positives? "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? # 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 # 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 "PT011", # pytest raises should is too broad
"PT012", # pytest raises should contain a single statement "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 "PD901", # generic variable name df
@ -125,15 +127,12 @@ lint.ignore = [
"TRY400", # TODO double check this, might be useful "TRY400", # TODO double check this, might be useful
"TRY401", # redundant exception in logging.exception call? TODO double check, might result in excessive logging "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 "PGH", # TODO force error code in mypy instead
# TODO enable TID?
"TID252", # Prefer absolute imports over relative imports from parent modules "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 ## too annoying
"T20", # just complains about prints and pprints "T20", # just complains about prints and pprints
"Q", # flake quotes, too annoying "Q", # flake quotes, too annoying
@ -144,5 +143,9 @@ lint.ignore = [
"BLE001", # do not catch 'blind' Exception "BLE001", # do not catch 'blind' Exception
"INP001", # complains about implicit namespace packages "INP001", # complains about implicit namespace packages
"SIM", # some if statements crap "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
] ]