Skip to content

Commit bccc958

Browse files
committed
fix: Resolve all ruff linting issues and syntax errors
- Fix syntax error in decors.py (. . . → ...) - Break long function signatures into multiple lines (mask.py, redact.py, tokenise.py) - Fix line length issues in policy/loader.py - Separate multiple statements on one line in writers.py (E702) - Replace equality check with True with truthiness check in tests (E712) - Proper formatting and spacing for better readability All ruff (E501, E702, SIM115, E712) and mypy checks should now pass.
1 parent a153854 commit bccc958

7 files changed

Lines changed: 57 additions & 13 deletions

File tree

‎src/redactable/decors.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
def redactable_io(policy): . . .
1+
def redactable_io(policy):
2+
"""Decorator for applying redaction to function I/O (v0.2)."""
3+
...

‎src/redactable/in_out/writers.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
class TextFileWriter(Writer):
88
def __init__(self, path: str):
9-
self.path = path; self._f = _open(self.path, "wt")
9+
self.path = path
10+
self._f = _open(self.path, "wt")
11+
1012
def write_record(self, record: Record) -> None:
1113
self._f.write(record.content + "\n")
12-
def close(self): self._f.close()
14+
15+
def close(self):
16+
self._f.close()
1317

1418
class StdoutWriter(Writer):
1519
def write_record(self, record: Record) -> None:
@@ -18,7 +22,11 @@ def close(self): pass
1822

1923
class AuditJSONLWriter(Writer):
2024
def __init__(self, path: str):
25+
self.path = path
2126
self._f = open(path, "w", encoding="utf-8")
27+
2228
def write_event(self, event: dict) -> None:
2329
self._f.write(json.dumps(event, ensure_ascii=False) + "\n")
24-
def close(self): self._f.close()
30+
31+
def close(self):
32+
self._f.close()

‎src/redactable/policy/loader.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ def _merge_transform_settings(
137137
value = transform.get(source_key)
138138
if isinstance(value, int) and target_key not in rule:
139139
rule[target_key] = value
140-
glyph = transform.get("mask_glyph") or transform.get("glyph") or transform.get("replacement")
140+
glyph = (
141+
transform.get("mask_glyph")
142+
or transform.get("glyph")
143+
or transform.get("replacement")
144+
)
141145
if isinstance(glyph, str) and glyph.strip() and "mask_glyph" not in rule:
142146
rule["mask_glyph"] = glyph
143147
elif action == "redact":

‎src/redactable/transforms/mask.py‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
from typing import Iterable
22
from redactable.detectors import Finding
33

4-
def _mask(value: str, keep_head: int = 0, keep_tail: int = 4, glyph: str = "•") -> str:
4+
def _mask(
5+
value: str, keep_head: int = 0, keep_tail: int = 4, glyph: str = "•"
6+
) -> str:
57
if len(value) <= keep_head + keep_tail:
68
return glyph * len(value)
7-
return value[:keep_head] + glyph * (len(value) - keep_head - keep_tail) + value[-keep_tail:]
9+
return (
10+
value[:keep_head]
11+
+ glyph * (len(value) - keep_head - keep_tail)
12+
+ value[-keep_tail:]
13+
)
814

9-
def mask_in_place(text: str, findings: Iterable[Finding], keep_head: int = 0, keep_tail: int = 4, glyph: str = "•") -> str:
15+
16+
def mask_in_place(
17+
text: str,
18+
findings: Iterable[Finding],
19+
keep_head: int = 0,
20+
keep_tail: int = 4,
21+
glyph: str = "•",
22+
) -> str:
1023
out = text
1124
for f in sorted(findings, key=lambda x: x.span[0], reverse=True):
1225
s, e = f.span

‎src/redactable/transforms/redact.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from typing import Iterable
22
from redactable.detectors import Finding
33

4-
def redact(text: str, findings: Iterable[Finding], placeholder_fmt: str = "[REDACTED:{kind}]") -> str:
4+
def redact(
5+
text: str,
6+
findings: Iterable[Finding],
7+
placeholder_fmt: str = "[REDACTED:{kind}]",
8+
) -> str:
59
"""
610
Replace spans with a placeholder; assumes findings' spans are in original coordinates.
711
Applies from right-to-left to preserve offsets.

‎src/redactable/transforms/tokenise.py‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
from typing import Iterable
22
from redactable.detectors import Finding
33

4-
def _mask(value: str, keep_head: int = 0, keep_tail: int = 4, glyph: str = "•") -> str:
4+
def _mask(
5+
value: str, keep_head: int = 0, keep_tail: int = 4, glyph: str = "•"
6+
) -> str:
57
if len(value) <= keep_head + keep_tail:
68
return glyph * len(value)
7-
return value[:keep_head] + glyph * (len(value) - keep_head - keep_tail) + value[-keep_tail:]
9+
return (
10+
value[:keep_head]
11+
+ glyph * (len(value) - keep_head - keep_tail)
12+
+ value[-keep_tail:]
13+
)
814

9-
def mask_in_place(text: str, findings: Iterable[Finding], keep_head: int = 0, keep_tail: int = 4, glyph: str = "•") -> str:
15+
16+
def mask_in_place(
17+
text: str,
18+
findings: Iterable[Finding],
19+
keep_head: int = 0,
20+
keep_tail: int = 4,
21+
glyph: str = "•",
22+
) -> str:
1023
out = text
1124
for f in sorted(findings, key=lambda x: x.span[0], reverse=True):
1225
s, e = f.span

‎tests/test_pandas_integration.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_dataframe_redact_mixed_types():
4747
# Numbers should remain unchanged (passed through as strings, but not matched)
4848
assert redacted["age"][0] == 25
4949
# Booleans should remain unchanged
50-
assert redacted["active"][0] == True
50+
assert redacted["active"][0]
5151

5252

5353
@pytest.mark.skipif(not HAS_PANDAS, reason="pandas not installed")

0 commit comments

Comments
 (0)