Skip to content

Commit 2870ae8

Browse files
dcarranza-axlclaude
andcommitted
fix: ruff lint - line length, import sorting, unused imports
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6de55e1 commit 2870ae8

7 files changed

Lines changed: 56 additions & 22 deletions

File tree

src/axl/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
__version__ = "0.8.0"
88

99
from axl.compressor import compress, english_to_v3
10-
from axl.decompressor import decompress, v3_to_english as decompress_to_claims, format_decompressed, parse_packet, strip_kernel
10+
from axl.decompressor import decompress, format_decompressed, parse_packet, strip_kernel
11+
from axl.decompressor import v3_to_english as decompress_to_claims
1112
from axl.emitter import emit, emit_v3, v3_from_json, v3_to_json
1213
from axl.models import (
1314
FLAGS,

src/axl/cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _do_parse(args: argparse.Namespace) -> None:
1616
version = detect_version(args.packet)
1717
if version == "v3":
1818
pkt = parse_v3(args.packet)
19-
print(f"Version: v3")
19+
print("Version: v3")
2020
print(f"ID : {pkt.id}")
2121
print(f"Op : {pkt.operation.value}.{pkt.confidence:02d}")
2222
print(f"Subject: {pkt.subject_tag.value}{pkt.subject_value}")
@@ -29,7 +29,7 @@ def _do_parse(args: argparse.Namespace) -> None:
2929
print(f"Meta : {pkt.meta}")
3030
else:
3131
packet = parse(args.packet)
32-
print(f"Version: v1")
32+
print("Version: v1")
3333
print(f"Domain : {packet.domain}")
3434
print(f"Tier : {packet.tier}")
3535
if packet.agent_id:
@@ -119,7 +119,7 @@ def _do_emit(args: argparse.Namespace) -> None:
119119

120120

121121
def _do_decompress(args: argparse.Namespace) -> None:
122-
from axl.decompressor import v3_to_english, format_decompressed, decompress
122+
from axl.decompressor import decompress, v3_to_english
123123

124124
with open(args.file) as f:
125125
text = f.read()
@@ -179,7 +179,9 @@ def main() -> None:
179179
# ── decompress ──
180180
p_decompress = subparsers.add_parser("decompress", help="Decompress AXL packets to English")
181181
p_decompress.add_argument("file", help="File containing AXL packets (use /dev/stdin for pipe)")
182-
p_decompress.add_argument("--raw", action="store_true", help="Print raw claims without grouping")
182+
p_decompress.add_argument(
183+
"--raw", action="store_true", help="Print raw claims without grouping"
184+
)
183185
p_decompress.set_defaults(func=_do_decompress)
184186

185187
# ── version ──

src/axl/compressor.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222

2323
import spacy
2424

25-
from axl.models import Operation, TagType, V3Packet
2625
from axl.emitter import emit_v3
27-
26+
from axl.models import Operation, TagType, V3Packet
2827

2928
# -- spaCy singleton ---------------------------------------------------------
3029

@@ -503,7 +502,9 @@ def extract_evidence(text: str, doc=None) -> Optional[str]:
503502

504503
def _is_pronoun_like(text: str) -> bool:
505504
stripped = text.strip().lower()
506-
return stripped in _PRONOUNS or bool(re.fullmatch(r"(?:i|you|we|they|he|she|it|this|that)", stripped))
505+
return stripped in _PRONOUNS or bool(
506+
re.fullmatch(r"(?:i|you|we|they|he|she|it|this|that)", stripped)
507+
)
507508

508509

509510
def _is_weak_subject(text: str) -> bool:
@@ -630,7 +631,9 @@ def extract_subject(
630631
# Fallback tokens.
631632
if not best:
632633
for tok in doc:
633-
if tok.pos_ in ("PROPN", "NOUN") and not tok.like_num and not _is_pronoun_like(tok.text):
634+
if (tok.pos_ in ("PROPN", "NOUN")
635+
and not tok.like_num
636+
and not _is_pronoun_like(tok.text)):
634637
tag, _ = classify_tag(tok.text)
635638
clean = _clean_token_value(tok.text, max_len=30, keep=".-")
636639
if clean:
@@ -683,7 +686,9 @@ def infer_role_label(ent, doc) -> Optional[str]:
683686
candidates.append((score, tok.text))
684687

685688
head = ent.root.head
686-
if head.pos_ in ("NOUN", "PROPN") and head.lemma_.lower() not in _ROLE_STOPWORDS and not head.like_num:
689+
if (head.pos_ in ("NOUN", "PROPN")
690+
and head.lemma_.lower() not in _ROLE_STOPWORDS
691+
and not head.like_num):
687692
candidates.append((28, head.text))
688693

689694
if not candidates:
@@ -829,9 +834,14 @@ def english_to_v3(text: str, agent_id: str = "COMPRESS") -> list[V3Packet]:
829834
operation = classify_operation(sent_text)
830835

831836
has_nums = bool(
832-
sent_doc.ents and any(e.label_ in ("MONEY", "QUANTITY", "CARDINAL", "PERCENT", "DATE") for e in sent_doc.ents)
837+
sent_doc.ents and any(
838+
e.label_ in ("MONEY", "QUANTITY", "CARDINAL", "PERCENT", "DATE")
839+
for e in sent_doc.ents
840+
)
841+
)
842+
has_ents = bool(
843+
sent_doc.ents and any(e.label_ in ("PERSON", "ORG", "GPE") for e in sent_doc.ents)
833844
)
834-
has_ents = bool(sent_doc.ents and any(e.label_ in ("PERSON", "ORG", "GPE") for e in sent_doc.ents))
835845
confidence = score_confidence(sent_text, operation, has_nums, has_ents)
836846

837847
tag_type, subject_value = extract_subject(sent_doc, sent_text, operation, context_subject)
@@ -892,7 +902,9 @@ def english_to_v3(text: str, agent_id: str = "COMPRESS") -> list[V3Packet]:
892902
if packets:
893903
has_entities = any(p.subject_tag == TagType.ENTITY for p in packets)
894904
has_numbers = any(p.arg2 and "^" in (p.arg2 or "") for p in packets)
895-
has_causality = any(p.arg1 and ("<-" in (p.arg1 or "") or "RE:" in (p.arg1 or "")) for p in packets)
905+
has_causality = any(
906+
p.arg1 and ("<-" in (p.arg1 or "") or "RE:" in (p.arg1 or "")) for p in packets
907+
)
896908
has_confidence = True
897909
has_temporal = any(
898910
p.temporal != "NOW" or (p.arg2 and "^date:" in p.arg2)

src/axl/decompressor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from collections import defaultdict
1414
from typing import Optional
1515

16-
1716
TAG_NAMES = {
1817
"$": "Financial",
1918
"@": "Entity",
@@ -247,7 +246,10 @@ def format_decompressed(claims: list[dict]) -> str:
247246

248247
groups: dict[tuple[str, str], list[dict]] = defaultdict(list)
249248
for claim in claims:
250-
key = (claim.get("tag", "^"), claim.get("base_subject") or claim.get("tag_value") or "unknown")
249+
key = (
250+
claim.get("tag", "^"),
251+
claim.get("base_subject") or claim.get("tag_value") or "unknown",
252+
)
251253
groups[key].append(claim)
252254

253255
for key in groups:

src/axl/translator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ def v3_to_english(packet: V3Packet) -> str:
367367

368368
if op == Operation.PRD:
369369
outcome = packet.arg2 or packet.arg1 or subj
370-
return f"{agent} predicts {subj} at {outcome} within {packet.temporal} with {cc}% confidence."
370+
return (
371+
f"{agent} predicts {subj} at {outcome} within {packet.temporal} with {cc}% confidence."
372+
)
371373

372374
return f"{agent}: {op.value}.{cc} {subj}"

src/axl/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
from axl.models import Operation, Packet, ValidationResult, ValidationWarning, V3Packet
8+
from axl.models import Operation, Packet, V3Packet, ValidationResult, ValidationWarning
99
from axl.schemas import (
1010
SCHEMAS,
1111
VALID_ACTIONS,

tests/test_decompressor.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
"""Tests for the AXL decompressor."""
2-
import pytest
3-
from axl.decompressor import parse_packet, strip_kernel, v3_to_english, format_decompressed, decompress
2+
from axl.decompressor import (
3+
decompress,
4+
format_decompressed,
5+
parse_packet,
6+
strip_kernel,
7+
v3_to_english,
8+
)
49

510

611
def test_parse_obs_packet():
@@ -37,7 +42,11 @@ def test_parse_malformed():
3742

3843

3944
def test_v3_to_english_basic():
40-
text = 'ID:a|OBS.95|$.BTC|^67420|NOW\nID:b|INF.80|@market|<-funding|~bullish|4H\nID:c|PRD.70|$.BTC|^69200|NOW'
45+
text = (
46+
'ID:a|OBS.95|$.BTC|^67420|NOW'
47+
'\nID:b|INF.80|@market|<-funding|~bullish|4H'
48+
'\nID:c|PRD.70|$.BTC|^69200|NOW'
49+
)
4150
claims = v3_to_english(text)
4251
assert len(claims) == 3
4352
assert claims[0]['op'] == 'OBS'
@@ -47,8 +56,14 @@ def test_v3_to_english_basic():
4756

4857
def test_format_grouped():
4958
claims = [
50-
{'op': 'OBS', 'cc': 95, 'tag': '$', 'tag_value': 'BTC', 'base_subject': 'BTC', 'aspect': None, 'claim_text': 'BTC is 67420 (95%)', 'temp': 'NOW', 'raw': ''},
51-
{'op': 'OBS', 'cc': 90, 'tag': '@', 'tag_value': 'market', 'base_subject': 'market', 'aspect': None, 'claim_text': 'market is active (90%)', 'temp': 'NOW', 'raw': ''},
59+
{
60+
'op': 'OBS', 'cc': 95, 'tag': '$', 'tag_value': 'BTC', 'base_subject': 'BTC',
61+
'aspect': None, 'claim_text': 'BTC is 67420 (95%)', 'temp': 'NOW', 'raw': '',
62+
},
63+
{
64+
'op': 'OBS', 'cc': 90, 'tag': '@', 'tag_value': 'market', 'base_subject': 'market',
65+
'aspect': None, 'claim_text': 'market is active (90%)', 'temp': 'NOW', 'raw': '',
66+
},
5267
]
5368
result = format_decompressed(claims)
5469
assert 'BTC' in result

0 commit comments

Comments
 (0)