Skip to content

refactor(infra): share permissive type-coercion helpers - #257

Merged
gbrlcustodio merged 1 commit into
devfrom
refactor/infra-coerce
May 30, 2026
Merged

refactor(infra): share permissive type-coercion helpers#257
gbrlcustodio merged 1 commit into
devfrom
refactor/infra-coerce

Conversation

@gbrlcustodio

Copy link
Copy Markdown
Member

Summary

Consolidate the maybe_<type> pattern scattered across the SDK and Auth packages behind a single pipefy_infra.coerce module. One source of truth, one set of edge-case guarantees (handles None, empty strings, inf / NaN, type mismatches consistently).

Why split out

Carved out of #154 as the foundational layer. Two follow-up PRs depend on this one: refactor/auth-responses (OAuth response dataclasses use optional_int / optional_str internally) and feat/154-device (the device login strategy).

Changes

  • New packages/infra/src/pipefy_infra/coerce.py exports optional_int, optional_str, try_int. The int-based helpers catch OverflowError alongside TypeError / ValueError.
  • Standardization pass across pre-existing ad-hoc sites:
    • pipefy_sdk/services/pipe_service.py drops _coerce_org_pipes_count for optional_int.
    • pipefy_sdk/utils/formatters.py drops the inline _coerce_int closure for try_int.
    • pipefy_sdk/services/observability_export_csv.py parses content-length via optional_int instead of an ad-hoc try/except.

Test plan

  • uv run pytest packages/infra/tests/ packages/sdk/tests/ (956 passed, 17 skipped)
  • 25 parametrized cases in test_coerce.py cover None, empty strings, inf/NaN, type mismatches, and the try_int value-passthrough contract
  • CI green

@gbrlcustodio
gbrlcustodio force-pushed the refactor/infra-coerce branch 2 times, most recently from 638baa3 to d9c5402 Compare May 30, 2026 21:33
Consolidate the `maybe_<type>` pattern scattered across the SDK and
Auth packages behind a single `pipefy_infra.coerce` module so callers
have one source of truth and one set of edge-case guarantees.

* New `pipefy_infra.coerce` exports `optional_int`, `optional_str`,
  and `try_int`. The int-based helpers catch `OverflowError` alongside
  `TypeError` / `ValueError` so `optional_int(float('inf'))` and
  `try_int(float('inf'))` honor their "None / value unchanged" contracts.

* `pipefy_sdk.services.pipe_service` drops the private
  `_coerce_org_pipes_count` and calls `optional_int` directly when
  parsing `Organization.pipesCount` for truncation checks.

* `pipefy_sdk.utils.formatters` drops the inline `_coerce_int` closure
  inside `coerce_graphql_condition` and routes through `try_int`.

* `pipefy_sdk.services.observability_export_csv` parses the
  `content-length` header via `optional_int` instead of an ad-hoc
  try/except. Same `None`-on-failure behavior; one fewer place to
  remember the exception set.

Tests: 25 parametrized cases in `packages/infra/tests/test_coerce.py`
covering `None`, empty strings, `inf` / `NaN`, type mismatches, and the
`try_int` value-passthrough contract. Existing SDK suites still pass.
@gbrlcustodio
gbrlcustodio force-pushed the refactor/infra-coerce branch from d9c5402 to 53fa1a9 Compare May 30, 2026 22:09
@gbrlcustodio gbrlcustodio self-assigned this May 30, 2026
@gbrlcustodio gbrlcustodio added the refactor Internal restructure with no intended user-facing behavior change label May 30, 2026
@gbrlcustodio
gbrlcustodio merged commit 5bddca1 into dev May 30, 2026
2 checks passed
@gbrlcustodio
gbrlcustodio deleted the refactor/infra-coerce branch May 30, 2026 22:13
@gbrlcustodio
gbrlcustodio restored the refactor/infra-coerce branch May 30, 2026 22:14
@gbrlcustodio
gbrlcustodio deleted the refactor/infra-coerce branch May 30, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Internal restructure with no intended user-facing behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant