Skip to content

fix: preserve result catch signatures without type ignores - #308

Merged
dbrattli merged 1 commit into
mainfrom
fix/result-catch-typing
Nov 12, 2026
Merged

dbrattli merged 1 commit into
mainfrom
fix/result-catch-typing

Conversation

@dbrattli

Copy link
Copy Markdown
Owner

catch required a type: ignore because its overloads disagreed with the implementation about keyword-only exception and the returned callable. Align both calling forms and use a generic decorator protocol with ParamSpec to preserve arguments, result payloads, and existing error channels, including stacked decorators.

For example, wrapping an (int) -> int function with catch(exception=ValueError) now retains its integer argument and returns Result[int, ValueError]; wrapping an existing Result[int, str] function returns Result[int, str | ValueError]. Incorrect argument types are rejected. Runtime behavior is unchanged.

Retain typing_extensions.TypeVar defaults for Python 3.12 compatibility and document why Never is needed to avoid an inferred unknown error channel. Add positive inference, runtime, and negative typing regression coverage.

Verification commands: pre-commit run --all-files --show-diff-on-failure, python -m pytest, and python scripts/check_docs.py.

@dbrattli
dbrattli merged commit 4913acc into main Nov 12, 2026
6 checks passed
@dbrattli
dbrattli deleted the fix/result-catch-typing branch November 12, 2026 15:29
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