agronholm / agronholm/typeguard

Enable typecheck_fail_callback to return a value

Open
#458 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
1.8k
Forks
145
Avg merge
8d 12h
Merged PRs (30d)
1

Description

### Things to check first

- [X] I have searched the existing issues and didn't find my feature already requested there

### Feature description

Currently typecheck_fail_callback can only be used for side effects. I am proposing that it should also be able to return a value and that check_type would then return that value.

### Use case

This lets us replace this:
```
x = None
try:
check_type(, )
except TypeCheckError as err:
x = some_function(err, z)
```
with the much cleaner and more elegant:
```
x = check_type(, , typecheck_fail_callback= partial(some_function, arg=z)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.