fix: remove unreachable backports.functools_lru_cache fallback

`functools.lru_cache` has been in the standard library since Python 3.2.
The project requires Python >=3.10, so the `except ImportError` branch
importing `backports.functools_lru_cache` can never execute.

Remove the try/except block and keep only the direct stdlib import.
Also remove `types-backports` from dev dependencies, `backports` from
`[tool.deptry.known_first_party]`, and `types-backports` from the
DEP002 ignore list in `pyproject.toml`.
This commit is contained in:
Willi Ballenthin
2026-04-22 17:18:39 +03:00
committed by Willi Ballenthin
parent 16fb277980
commit 316aeaf8e5
4 changed files with 5 additions and 16 deletions
+1
View File
@@ -32,6 +32,7 @@
- fix: loader.py reads entire file for magic byte check @williballenthin #3029
- fix: freeze/__init__.py: logically impossible condition @williballenthin #3030
- fix: EXTENSIONS_ELF never referenced @williballenthin #3031
- fix: remove unreachable backports.functools_lru_cache fallback and dead dependency @williballenthin
### capa Explorer Web
+4 -12
View File
@@ -23,18 +23,9 @@ import logging
import binascii
import collections
from enum import Enum
from pathlib import Path
from capa.helpers import assert_never
try:
from functools import lru_cache
except ImportError:
# need to type ignore this due to mypy bug here (duplicate name):
# https://github.com/python/mypy/issues/1153
from backports.functools_lru_cache import lru_cache # type: ignore
from typing import Any, Union, Callable, Iterator, Optional, cast
from pathlib import Path
from functools import lru_cache
from dataclasses import asdict, dataclass
import yaml
@@ -51,6 +42,7 @@ import capa.features.insn
import capa.features.common
import capa.features.basicblock
from capa.engine import Statement, FeatureSet
from capa.helpers import assert_never
from capa.features.com import ComType
from capa.features.common import MAX_BYTES_FEATURE_SIZE, Feature
from capa.features.address import Address
@@ -1129,7 +1121,7 @@ class Rule:
return cls(name, scopes, build_statements(statements[0], scopes), meta, definition) # type: ignore[arg-type] # build_statements infers wide union but top-level always returns Statement
@staticmethod
@lru_cache()
@lru_cache
def _get_yaml_loader():
try:
# prefer to use CLoader to be fast, see #306 / CSafeLoader is the same as CLoader but with safe loading
-3
View File
@@ -139,7 +139,6 @@ dev = [
"PyGithub==2.9.0",
"bump-my-version==1.3.0",
# type stubs for mypy
"types-backports==0.1.3",
"types-colorama==0.4.15.11",
"types-PyYAML==6.0.8",
"types-psutil==7.2.0.20251228",
@@ -178,7 +177,6 @@ extend_exclude = [
# dependencies marked as first party, to inform deptry that they are local
known_first_party = [
"backports",
"binaryninja",
"flirt",
"ghidra",
@@ -219,7 +217,6 @@ DEP002 = [
"pytest-sugar",
"ruff",
"setuptools",
"types-backports",
"types-colorama",
"types-protobuf",
"types-psutil",
-1
View File
@@ -106,7 +106,6 @@ def test_is_dev_environment():
assert capa.helpers.is_dev_environment() is True
<<<<<<< HEAD
def test_load_one_jsonl_from_path_gz():
result = capa.helpers.load_one_jsonl_from_path(DRAKVUF_LOG_GZ)
assert isinstance(result, dict)