diff --git a/cpematcher/core.py b/cpematcher/core.py index e60d1a8..46f5130 100644 --- a/cpematcher/core.py +++ b/cpematcher/core.py @@ -66,7 +66,7 @@ def __init__( self.version_end_including = Version(version_end_including) self.version_end_excluding = Version(version_end_excluding) - def matches(self, another_cpe): + def matches(self, another_cpe): # noqa: C901 """Verify if `another_cpe` matches, first through field comparison and then using the border constraints. @@ -131,7 +131,7 @@ class CPEOperation: def _get_value(self, cpe_dict, key): for k in self.VERSION_MAP[key]: - if k in cpe_dict.keys(): + if k in cpe_dict: return cpe_dict[k] return None diff --git a/cpematcher/utils.py b/cpematcher/utils.py index 6ce9f32..6939ddd 100644 --- a/cpematcher/utils.py +++ b/cpematcher/utils.py @@ -1,3 +1,6 @@ +import contextlib + + # heavily inspired by https://stackoverflow.com/a/21882672 def split_cpe_string(string): ret = [] @@ -5,11 +8,9 @@ def split_cpe_string(string): itr = iter(string) for ch in itr: if ch == "\\": - try: + with contextlib.suppress(StopIteration): # skip the next character; it has been escaped! current.append(next(itr)) - except StopIteration: - pass elif ch == ":": # split! (add current to the list and reset it) ret.append("".join(current)) diff --git a/pyproject.toml b/pyproject.toml index f1bffa4..bda6886 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,3 +30,37 @@ pre-commit = "^3.5.0" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.ruff] +target-version = "py311" + +select = [ + "C90", # mccabe + "C4", # flake8-comprehensions + "COM818", # flake8-commas; trailing-comma-on-bare-tuple + "E", # pycodestyle (errors) + "F", # pyflakes + "I", # isort + "ISC", # flake8-implicit-str-concats + "PIE", # flake8-pie + "RUF", # ruff's own lints + "SIM", # flake8-simplify + "UP", # pyupgrade + "W", # pycodestyle (warnings) +] + +ignore = [ + "E501", # line-too-long: Let black handle line length violations + "RUF012", # mutable-class-default: Wants to annotate things like `__mapper_args__` with `ClassVar`, producing noise +] + +# Do not remove unused imports automatically in __init__.py files +ignore-init-module-imports = true + +[tool.ruff.per-file-ignores] +"*/__init__.py" = [ + "F401" +] + +[tool.ruff.mccabe] +max-complexity = 5