Skip to content

fix(result): p.Result DIP without lazy FlextResult in _result - #366

Merged
marlon-costa-dc merged 1 commit into
0.12.0-devfrom
bugfix/mro-bn0q.1-result-typing
Aug 4, 2026
Merged

fix(result): p.Result DIP without lazy FlextResult in _result#366
marlon-costa-dc merged 1 commit into
0.12.0-devfrom
bugfix/mro-bn0q.1-result-typing

Conversation

@marlon-costa-dc

@marlon-costa-dc marlon-costa-dc commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Remove regressive lazy FlextResult imports from _result/*.py
  • Type factories/transforms/composition as p.Result (DIP); construct via cls(...)
  • Keep public r[T] concrete via TYPE_CHECKING stubs on FlextResult

Test plan

  • make check CHECK_GATES=lint,format,pyrefly,mypy,pyright PROJECT=flext-core (exit 0)

Bead: mro-bn0q.1


Summary by cubic

Fixes result typing regressions by removing lazy FlextResult imports from _result/* and switching factories/transforms/composition to the abstract p.Result protocol. Keeps the public r[T] facade intact and aligns with mro-bn0q.1.

  • Bug Fixes

    • Removed lazy FlextResult imports in _result/* to prevent import cycles and mypy/pyright issues.
    • Made p.Result payload invariant to match usage and avoid unsound variance.
  • Refactors

    • Typed all factories/transforms/composition to p.Result and construct via cls(...) only.
    • Added TYPE_CHECKING stubs so r[T] stays concrete; introduced checks via FlextResultBase for successful_result/failed_result.
    • Used targeted cast(...) where needed and updated tests to annotate with p.Result[T].

Written for commit 56d7675. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Improvements

    • Standardized result operations around the public Result contract.
    • Improved type checking for result creation, transformation, error handling, and recovery.
    • Preserved existing runtime behavior while making result APIs more consistent and predictable.
  • Tests

    • Updated integration and unit coverage to validate the public result type across common workflows.

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 610860b2-4d78-4acb-9c06-330af5325783

📥 Commits

Reviewing files that changed from the base of the PR and between d5d87c6 and 56d7675.

📒 Files selected for processing (14)
  • src/flext_core/_protocols/result.py
  • src/flext_core/_result/composition.py
  • src/flext_core/_result/construction.py
  • src/flext_core/_result/transforms.py
  • src/flext_core/result.py
  • tests/integration/test_documented_patterns.py
  • tests/integration/test_integration.py
  • tests/integration/test_migration_validation.py
  • tests/integration/test_system.py
  • tests/unit/test_deprecation_warnings.py
  • tests/unit/test_result.py
  • tests/unit/test_result_callables_fold.py
  • tests/unit/test_result_chain_helpers.py
  • tests/unit/test_result_laws.py

📝 Walkthrough

Walkthrough

The PR changes Result from covariant to invariant typing. Result construction, transformations, and composition helpers now expose p.Result contracts. Tests update local annotations to use the protocol type.

Changes

Result typing alignment

Layer / File(s) Summary
Invariant Result protocol contract
src/flext_core/_protocols/result.py
Result now uses invariant ResultT across value, unwrapping, transformation, side-effect, filtering, and recovery methods.
Protocol-based construction API
src/flext_core/_result/construction.py, src/flext_core/result.py
Construction methods use p.Result and FlextResultBase. The public FlextResult facade declares typed class methods. copy_from_result replaces _from_result.
Typed composition and transformations
src/flext_core/_result/composition.py, src/flext_core/_result/transforms.py
Helpers return p.Result types and use casts for generic failure paths. Runtime behavior remains unchanged.
Protocol annotation updates in tests
tests/integration/*, tests/unit/*
Test-local result annotations use p.Result instead of concrete r types. Assertions and behavior checks remain unchanged.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: using p.Result and removing lazy FlextResult imports in _result.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/mro-bn0q.1-result-typing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Aug 4, 2026

Copy link
Copy Markdown

@marlon-costa-dc
marlon-costa-dc merged commit bc124ac into 0.12.0-dev Aug 4, 2026
3 of 6 checks passed
@marlon-costa-dc
marlon-costa-dc deleted the bugfix/mro-bn0q.1-result-typing branch August 4, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant