From 029f2a1b07c13722645007d9f3f7d0a98ecaac99 Mon Sep 17 00:00:00 2001
From: Chris Markiewicz <effigies@gmail.com>
Date: Sun, 5 Nov 2023 12:38:26 -0500
Subject: [PATCH] STY: Fix style issues (#58)

* RUN: hatch run lint:fmt

* STY: Ignore FBT002, allow F401 to be fixed

* Use functools.wraps for the shutil.rmtree wrapper in conftest.py

Fixes mypy error:

  tests/conftest.py:18:5: error: Incompatible redefinition (redefinition with
  type "Callable[[Any, Any, Any, VarArg(Any), KwArg(Any)], Any]", original type
  "_RmtreeType")  [misc]
          def rmtree(path, ignore_errors=False, onerror=None, *args, **kwds)...
          ^
  tests/conftest.py:18:5: note: "function" is missing following "_RmtreeType" protocol member:
  tests/conftest.py:18:5: note:     avoids_symlink_attacks

* STY: Ignore bandit false positives

---------

Co-authored-by: Benjamin A. Beasley <code@musicinmybrain.net>
---
 pyproject.toml    |  8 ++++----
 tests/conftest.py | 11 +++++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 947b862..fbaa025 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -83,10 +83,10 @@ ignore = [
   "FBT003",
   # Ignore checks for possible passwords
   "S105", "S106", "S107",
-]
-unfixable = [
-  # Don't touch unused imports
-  "F401",
+  # Ignore noisy checks for insecure subprocess calls
+  "S603", "S607",
+  # Boolean default values
+  "FBT002",
 ]
 
 [tool.ruff.isort]
diff --git a/tests/conftest.py b/tests/conftest.py
index 2ae094c..9179244 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,10 +3,10 @@
 # SPDX-License-Identifier: MIT
 import errno
 import os
-import shutil
 import stat
 import tempfile
 from contextlib import contextmanager
+from functools import wraps
 from sys import version_info
 
 if version_info[:2] >= (3, 12):
@@ -14,16 +14,19 @@
 else:
     from shutil import rmtree as _rmtree
 
-    # Wrap rmtree to backport the onexc keyword argument from Python 3.12
+    # Backport the onexc keyword argument from Python 3.12
+    @wraps(_rmtree)
     def rmtree(path, ignore_errors=False, onerror=None, *args, **kwds):
-        if "onexc" in kwds:
+        if 'onexc' in kwds:
             kwds = dict(kwds)
-            onexc = kwds.pop("onexc")
+            onexc = kwds.pop('onexc')
 
             def onerror(func, path, exc):
                 return onexc(func, path, exc[1])
+
         return _rmtree(path, ignore_errors, onerror, *args, **kwds)
 
+
 import pytest
 
 from .utils import create_file, git, write_file