diff --git a/.github/flake8.ini b/.github/flake8.ini index f949f8015..6426764fb 100644 --- a/.github/flake8.ini +++ b/.github/flake8.ini @@ -10,6 +10,8 @@ extend-ignore = F811, # E501 line too long (prefer black) E501, + # E701 multiple statements on one line (colon) (prefer black, see https://github.com/psf/black/issues/4173) + E701, # B010 Do not call setattr with a constant attribute value B010, # G200 Logging statement uses exception in arguments diff --git a/capa/features/address.py b/capa/features/address.py index 800cefcd3..0edf4cec2 100644 --- a/capa/features/address.py +++ b/capa/features/address.py @@ -10,8 +10,7 @@ class Address(abc.ABC): @abc.abstractmethod - def __eq__(self, other): - ... + def __eq__(self, other): ... @abc.abstractmethod def __lt__(self, other): diff --git a/capa/features/freeze/__init__.py b/capa/features/freeze/__init__.py index 2dac7f48e..258ba07a8 100644 --- a/capa/features/freeze/__init__.py +++ b/capa/features/freeze/__init__.py @@ -9,6 +9,7 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + import json import zlib import logging diff --git a/capa/ida/plugin/form.py b/capa/ida/plugin/form.py index ddd4c4e0d..301ead723 100644 --- a/capa/ida/plugin/form.py +++ b/capa/ida/plugin/form.py @@ -932,9 +932,9 @@ def get_ask_use_persistent_cache(self, analyze): update_wait_box("verifying cached results") try: - results: Optional[ - capa.render.result_document.ResultDocument - ] = capa.ida.helpers.load_and_verify_cached_results() + results: Optional[capa.render.result_document.ResultDocument] = ( + capa.ida.helpers.load_and_verify_cached_results() + ) except Exception as e: capa.ida.helpers.inform_user_ida_ui("Failed to verify cached results, reanalyzing program") logger.exception("Failed to verify cached results (error: %s)", e) diff --git a/capa/ida/plugin/view.py b/capa/ida/plugin/view.py index 0225e453c..bbb8287a2 100644 --- a/capa/ida/plugin/view.py +++ b/capa/ida/plugin/view.py @@ -200,9 +200,11 @@ def load_preview_meta(self, ea, author, scope): " references:", " - ", " examples:", - f" - {capa.ida.helpers.get_file_md5().upper()}:{hex(ea)}" - if ea - else f" - {capa.ida.helpers.get_file_md5().upper()}", + ( + f" - {capa.ida.helpers.get_file_md5().upper()}:{hex(ea)}" + if ea + else f" - {capa.ida.helpers.get_file_md5().upper()}" + ), " features:", ] self.setText("\n".join(metadata_default)) diff --git a/capa/loader.py b/capa/loader.py index 4c0f3d4f0..a8ffccf0f 100644 --- a/capa/loader.py +++ b/capa/loader.py @@ -482,7 +482,7 @@ def result_rec(result: capa.features.common.Result): ) for t in threads if t in matched_threads - ) # this object is open to extension in the future, + ), # this object is open to extension in the future, # such as with the function name, etc. ) for p, threads in threads_by_process.items() @@ -524,7 +524,7 @@ def compute_static_layout(rules: RuleSet, extractor: StaticFeatureExtractor, cap address=frz.Address.from_capa(f), matched_basic_blocks=tuple( rdoc.BasicBlockLayout(address=frz.Address.from_capa(bb)) for bb in bbs if bb in matched_bbs - ) # this object is open to extension in the future, + ), # this object is open to extension in the future, # such as with the function name, etc. ) for f, bbs in bbs_by_function.items() diff --git a/capa/render/result_document.py b/capa/render/result_document.py index 2ef85185e..ce95245e0 100644 --- a/capa/render/result_document.py +++ b/capa/render/result_document.py @@ -160,8 +160,7 @@ class CompoundStatementType: OPTIONAL = "optional" -class StatementModel(FrozenModel): - ... +class StatementModel(FrozenModel): ... class CompoundStatement(StatementModel): @@ -650,9 +649,9 @@ def from_capa(cls, meta: Metadata, rules: RuleSet, capabilities: MatchResults) - return ResultDocument(meta=meta, rules=rule_matches) def to_capa(self) -> Tuple[Metadata, Dict]: - capabilities: Dict[ - str, List[Tuple[capa.features.address.Address, capa.features.common.Result]] - ] = collections.defaultdict(list) + capabilities: Dict[str, List[Tuple[capa.features.address.Address, capa.features.common.Result]]] = ( + collections.defaultdict(list) + ) # this doesn't quite work because we don't have the rule source for rules that aren't matched. rules_by_name = { diff --git a/capa/render/verbose.py b/capa/render/verbose.py index f6f566dec..44024acf4 100644 --- a/capa/render/verbose.py +++ b/capa/render/verbose.py @@ -22,6 +22,7 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + from typing import cast import tabulate diff --git a/pyproject.toml b/pyproject.toml index 62ed5ef7a..08dc82700 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,7 @@ dev = [ "flake8-use-pathlib==0.3.0", "flake8-copyright==0.2.4", "ruff==0.1.14", - "black==23.12.1", + "black==24.1.1", "isort==5.13.2", "mypy==1.8.0", "psutil==5.9.2", diff --git a/scripts/cache-ruleset.py b/scripts/cache-ruleset.py index 0e364622b..8a10cf504 100644 --- a/scripts/cache-ruleset.py +++ b/scripts/cache-ruleset.py @@ -15,6 +15,7 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + import sys import logging import argparse diff --git a/scripts/capafmt.py b/scripts/capafmt.py index de4171ea8..be46b2ade 100644 --- a/scripts/capafmt.py +++ b/scripts/capafmt.py @@ -14,6 +14,7 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + import sys import logging import argparse diff --git a/scripts/import-to-ida.py b/scripts/import-to-ida.py index e52a029d2..3c6533047 100644 --- a/scripts/import-to-ida.py +++ b/scripts/import-to-ida.py @@ -28,6 +28,7 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + import logging import binascii from pathlib import Path diff --git a/scripts/lint.py b/scripts/lint.py index 93440395d..49ff70e6a 100644 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -13,6 +13,7 @@ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + import gc import os import re