Skip to content

Commit

Permalink
Lint stricter
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Jul 4, 2023
1 parent 0088d91 commit 4da64d2
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 54 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- "pypy-3.7"
- "pypy-3.8"
- "pypy-3.9"
- "pypy-3.10"

steps:
- uses: actions/checkout@v3
Expand Down
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
14 changes: 0 additions & 14 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
# 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"

Expand Down Expand Up @@ -68,17 +65,6 @@
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]).
Expand Down
55 changes: 32 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/argon2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/argon2/_password_hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import os

from typing import ClassVar

from ._typing import Literal
from ._utils import Parameters, _check_types, extract_parameters
from .exceptions import InvalidHashError
Expand Down Expand Up @@ -164,7 +166,7 @@ def hash(self, password: str | bytes) -> str:
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,
Expand Down Expand Up @@ -209,7 +211,7 @@ def verify(
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
Expand Down
2 changes: 1 addition & 1 deletion src/argon2/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions src/argon2/low_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
7 changes: 4 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: MIT

from base64 import b64encode
from dataclasses import replace

import pytest

Expand Down Expand Up @@ -112,10 +113,10 @@ def test_invalid_hash(self, hash):
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):
"""
Expand Down

0 comments on commit 4da64d2

Please sign in to comment.