Skip to content

Commit c24c354

Browse files
vvillait88claude
andcommitted
fix(payment): address github-code-quality bot review on PR #53
- Wrap the warn-once flag in a _WarnedFlags class so the symbol is referenced at module scope (was: bare module-level bool only mutated via `global`, which the lint pass flagged as unused at module scope). - Drop the per-test `import compose_rails as mod` indirection; reset via _WarnedFlags directly. Eliminates the mixed `import` / `from import` styles bot complaint on test_compose_rails.py. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f9ea807 commit c24c354

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

‎agentscore_commerce/payment/compose_rails.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@
2020
from agentscore_commerce.payment.usdc import USDC
2121

2222
_SOLANA_MAINNET_CAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
23-
_warned_stripe_below_minimum = False
2423
_logger = logging.getLogger(__name__)
2524

2625

26+
class _WarnedFlags:
27+
"""Warn-once flags for helpers that shouldn't spam logs.
28+
29+
Wrapped in a class instead of a bare module-level bool so the symbol is
30+
referenced at module scope rather than mutated only via ``global``.
31+
"""
32+
33+
stripe_below_minimum: bool = False
34+
35+
2736
def build_mppx_compose_rails(
2837
*,
2938
amount_usd: str,
@@ -104,9 +113,8 @@ def build_mppx_compose_rails(
104113
except (InvalidOperation, TypeError, ValueError):
105114
amount_decimal = None
106115
if amount_decimal is not None and amount_decimal < STRIPE_MIN_CHARGE_USD:
107-
global _warned_stripe_below_minimum
108-
if not _warned_stripe_below_minimum:
109-
_warned_stripe_below_minimum = True
116+
if not _WarnedFlags.stripe_below_minimum:
117+
_WarnedFlags.stripe_below_minimum = True
110118
_logger.warning(
111119
"[build_mppx_compose_rails] Dropping stripe/charge rail: amount_usd=%s is below "
112120
"Stripe's $%s USD minimum. Stripe's fixed ~$0.30 fee makes sub-50-cent charges "

‎tests/test_compose_rails.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from agentscore_commerce.payment.compose_rails import build_mppx_compose_rails
5+
from agentscore_commerce.payment.compose_rails import _WarnedFlags, build_mppx_compose_rails
66

77

88
def test_emits_single_tempo_intent_when_only_tempo_recipient() -> None:
@@ -57,9 +57,7 @@ def test_raises_when_amount_unparseable_with_solana_rail() -> None:
5757

5858

5959
def test_auto_drops_stripe_when_amount_below_min(caplog: pytest.LogCaptureFixture) -> None:
60-
import agentscore_commerce.payment.compose_rails as mod
61-
62-
mod._warned_stripe_below_minimum = False # reset module-level warn-once flag
60+
_WarnedFlags.stripe_below_minimum = False # reset module-level warn-once flag
6361
with caplog.at_level("WARNING"):
6462
rails = build_mppx_compose_rails(amount_usd="0.01", tempo_recipient="0xabc")
6563
assert all(r[0] != "stripe/charge" for r in rails)

0 commit comments

Comments
 (0)