Skip to content

Commit

Permalink
STY: Fix style issues (#58)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
effigies and musicinmybrain authored Nov 5, 2023
1 parent c39a6cc commit 029f2a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 7 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@
# 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):
from shutil import rmtree
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
Expand Down

0 comments on commit 029f2a1

Please sign in to comment.