refactor(infra): share permissive type-coercion helpers#257
Merged
Conversation
This was referenced May 30, 2026
638baa3 to
d9c5402
Compare
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.
d9c5402 to
53fa1a9
Compare
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consolidate the
maybe_<type>pattern scattered across the SDK and Auth packages behind a singlepipefy_infra.coercemodule. One source of truth, one set of edge-case guarantees (handlesNone, 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 useoptional_int/optional_strinternally) andfeat/154-device(the device login strategy).Changes
packages/infra/src/pipefy_infra/coerce.pyexportsoptional_int,optional_str,try_int. The int-based helpers catchOverflowErroralongsideTypeError/ValueError.pipefy_sdk/services/pipe_service.pydrops_coerce_org_pipes_countforoptional_int.pipefy_sdk/utils/formatters.pydrops the inline_coerce_intclosure fortry_int.pipefy_sdk/services/observability_export_csv.pyparsescontent-lengthviaoptional_intinstead of an ad-hoc try/except.Test plan
uv run pytest packages/infra/tests/ packages/sdk/tests/(956 passed, 17 skipped)test_coerce.pycoverNone, empty strings,inf/NaN, type mismatches, and thetry_intvalue-passthrough contract