Skip to content

Commit

Permalink
Add pep8-naming and flake8-bandit rules to Ruff (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored Jan 29, 2025
1 parent 27b44fe commit ae06c98
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dissect/util/cpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _swap16(value: int) -> int:
return ((value & 0xFF) << 8) | (value >> 8)


def CpioFile(*args, **kwargs) -> tarfile.TarFile:
def CpioFile(*args, **kwargs) -> tarfile.TarFile: # noqa: N802
"""Utility wrapper around ``tarfile.TarFile`` to easily open cpio archives."""
kwargs.setdefault("format", FORMAT_CPIO_UNKNOWN)
return tarfile.TarFile(*args, **kwargs, tarinfo=CpioInfo)
Expand Down
4 changes: 2 additions & 2 deletions dissect/util/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Feature(Enum):
DISSECT_FEATURES_ENV = "DISSECT_FEATURES"


class FeatureException(RuntimeError):
class FeatureError(RuntimeError):
pass


Expand Down Expand Up @@ -60,7 +60,7 @@ def my_func( ... ) -> ...
if alternative is None:

def alternative() -> NoReturn:
raise FeatureException(
raise FeatureError(
"\n".join(
[
"Feature disabled.",
Expand Down
9 changes: 5 additions & 4 deletions dissect/util/ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def uuid1timestamp(ts: int) -> datetime:
return _calculate_timestamp(float(ts) * 1e-7 - 12219292800)


DOS_EPOCH_YEAR = 1980


def dostimestamp(ts: int, centiseconds: int = 0, swap: bool = False) -> datetime:
"""Converts MS-DOS timestamps to naive datetime objects.
Expand All @@ -243,15 +246,13 @@ def dostimestamp(ts: int, centiseconds: int = 0, swap: bool = False) -> datetime
According to http://www.vsft.com/hal/dostime.htm
Args:
timestap: MS-DOS timestamp
centisecond: Optional ExFAT centisecond offset. Yes centisecond...
ts: MS-DOS timestamp
centiseconds: Optional ExFAT centisecond offset. Yes centisecond...
swap: Optional swap flag if date and time bytes are swapped.
Returns:
Datetime object from the passed timestamp.
"""
DOS_EPOCH_YEAR = 1980

# MS-DOS Date Time Format is actually 2 UINT16_T's first 16 bits are the time, second 16 bits are date
# the year is an offset of the MS-DOS epoch year, which is 1980

Expand Down
2 changes: 1 addition & 1 deletion dissect/util/xmemoryview.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def xmemoryview(view: bytes, format: str) -> memoryview | _xmemoryview:
return _xmemoryview(view, format)


class _xmemoryview:
class _xmemoryview: # noqa: N801
"""Wrapper for memoryview that converts between host and a different destination endianness.
Args:
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ select = [
"E",
"W",
"I",
"N",
"UP",
"YTT",
"ANN",
"S",
"B",
"C4",
"DTZ",
Expand All @@ -86,10 +88,11 @@ select = [
"FURB",
"RUF",
]
ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "SIM105", "TRY003"]
ignore = ["E203", "B904", "UP024", "ANN002", "ANN003", "ANN204", "ANN401", "S110", "SIM105", "TRY003"]

[tool.ruff.lint.per-file-ignores]
"tests/docs/**" = ["INP001"]
"tests/**" = ["S101"]

[tool.ruff.lint.isort]
known-first-party = ["dissect.util"]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_feature.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from dissect.util.feature import Feature, FeatureException, feature, feature_enabled
from dissect.util.feature import Feature, FeatureError, feature, feature_enabled


def test_feature_flags() -> None:
Expand All @@ -26,7 +26,7 @@ def expert() -> bool:
assert experimental() is False
assert advanced() is False
assert latest() is True
with pytest.raises(FeatureException):
with pytest.raises(FeatureError):
assert expert() is True


Expand Down
4 changes: 1 addition & 3 deletions tests/test_plist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import plistlib
import sys
import uuid
from plistlib import UID
from unittest.mock import patch

import pytest
Expand All @@ -11,8 +11,6 @@

@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
def test_plist_nskeyedarchiver() -> None:
UID = plistlib.UID

data = {
"$version": 100000,
"$archiver": "NSKeyedArchiver",
Expand Down

0 comments on commit ae06c98

Please sign in to comment.