Lint stricter

This commit is contained in:
Hynek Schlawack 2023-07-04 09:07:31 +02:00
parent 0088d913e8
commit 4da64d2ed4
No known key found for this signature in database
GPG Key ID: AE2536227F69F181
9 changed files with 47 additions and 54 deletions

View File

@ -36,6 +36,7 @@ jobs:
- "pypy-3.7"
- "pypy-3.8"
- "pypy-3.9"
- "pypy-3.10"
steps:
- uses: actions/checkout@v3

View File

@ -2,18 +2,14 @@
ci:
autoupdate_schedule: monthly
default_language_version:
# Keep in sync with .python-version.
python: python3.11
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.272
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.276
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

View File

@ -24,9 +24,6 @@ templates_path = ["_templates"]
# The suffix of source filenames.
source_suffix = ".rst"
# The encoding of source files.
# source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = "index"
@ -68,17 +65,6 @@ html_theme = "furo"
htmlhelp_basename = "argon2-cffidoc"
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).

View File

@ -95,7 +95,7 @@ branch = true
source = ["argon2"]
[tool.coverage.paths]
source = ["src", ".tox/**/site-packages"]
source = ["src", ".tox/py*/**/site-packages"]
[tool.coverage.report]
show_missing = true
@ -139,33 +139,42 @@ line-length = 79
[tool.ruff]
src = ["src", "tests", "noxfile.py"]
select = [
"E", # pycodestyle
"W", # pycodestyle
"F", # Pyflakes
"UP", # pyupgrade
"N", # pep8-naming
"YTT", # flake8-2020
"S", # flake8-bandit
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"T10", # flake8-debugger
"ISC", # flake8-implicit-str-concat
"RET", # flake8-return
"SIM", # flake8-simplify
"DTZ", # flake8-datetimez
"I", # isort
"PGH", # pygrep-hooks
"PLC", # Pylint
"PIE", # flake8-pie
"RUF", # ruff
]
select = ["ALL"]
ignore = [
"RUF001", # leave my smart characters alone
"A001", # shadowing is fine
"A002", # shadowing is fine
"A003", # shadowing is fine
"ANN", # Mypy is better at this
"ARG001", # unused arguments are normal when implementing interfaces
"COM", # Black takes care of our commas
"D", # We prefer our own docstring style.
"E501", # leave line-length enforcement to Black
"ERA001", # Dead code detection is overly eager.
"FBT", # we have one function that takes one bool; c'mon!
"FIX", # Yes, we want XXX as a marker.
"INP001", # sometimes we want Python files outside of packages
"PLR0913", # yes, many arguments, but most have defaults
"PLR2004", # numbers are sometimes fine
"PLW2901", # re-assigning within loop bodies is fine
"RUF001", # leave my smart characters alone
"SLF001", # private members are accessed by friendly functions
"TCH", # TYPE_CHECKING blocks break autodocs
"TD", # we don't follow other people's todo style
]
[tool.ruff.per-file-ignores]
"src/argon2/__main__.py" = ["T201"] # need print in CLI
"tests/*" = [
"ARG", # stubs don't care about arguments
"S101", # assert
"SIM300", # Yoda rocks in asserts
"PT005", # we always add underscores and explicit name
"PT011", # broad is fine
"TRY002", # stock exceptions are fine in tests
"EM101", # no need for exception msg hygiene in tests
]
[tool.ruff.isort]
lines-between-types = 1
lines-after-imports = 2

View File

@ -53,7 +53,8 @@ def __getattr__(name: str) -> str:
"__email__": "",
}
if name not in dunder_to_metadata.keys():
raise AttributeError(f"module {__name__} has no attribute {name}")
msg = f"module {__name__} has no attribute {name}"
raise AttributeError(msg)
import sys
import warnings

View File

@ -4,6 +4,8 @@ from __future__ import annotations
import os
from typing import ClassVar
from ._typing import Literal
from ._utils import Parameters, _check_types, extract_parameters
from .exceptions import InvalidHashError
@ -164,7 +166,7 @@ class PasswordHasher:
type=self.type,
).decode("ascii")
_header_to_type = {
_header_to_type: ClassVar[dict[bytes, Type]] = {
b"$argon2i$": Type.I,
b"$argon2d$": Type.D,
b"$argon2id": Type.ID,
@ -209,7 +211,7 @@ class PasswordHasher:
try:
hash_type = self._header_to_type[hash[:9]]
except LookupError:
raise InvalidHashError() from None
raise InvalidHashError from None
return verify_secret(
hash, _ensure_bytes(password, self.encoding), hash_type

View File

@ -125,7 +125,7 @@ def extract_parameters(hash: str) -> Parameters:
s.split("=") for s in [parts[2], *parts[3].split(",")]
)
}
except Exception:
except Exception: # noqa: BLE001
raise InvalidHashError from None
if sorted(kvs.keys()) != _REQUIRED_KEYS:

View File

@ -254,7 +254,4 @@ def error_to_str(error: int) -> str:
.. versionadded:: 16.0.0
"""
msg = ffi.string(lib.argon2_error_message(error))
msg = msg.decode("ascii")
return msg # type: ignore[no-any-return]
return ffi.string(lib.argon2_error_message(error)).decode("ascii") # type: ignore[no-any-return]

View File

@ -1,6 +1,7 @@
# SPDX-License-Identifier: MIT
from base64 import b64encode
from dataclasses import replace
import pytest
@ -112,10 +113,10 @@ class TestExtractParameters:
class TestParameters:
def test_eq(self):
"""
Parameters are iff every attribute is equal.
Parameters are equal iff every attribute is equal.
"""
assert VALID_PARAMETERS == VALID_PARAMETERS
assert VALID_PARAMETERS == VALID_PARAMETERS
assert VALID_PARAMETERS == VALID_PARAMETERS # noqa: PLR0124
assert VALID_PARAMETERS != replace(VALID_PARAMETERS, salt_len=9)
def test_eq_wrong_type(self):
"""