Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable typecheck_fail_callback to return a value #458

Open
1 task done
decision-dev opened this issue Apr 28, 2024 · 0 comments
Open
1 task done

Enable typecheck_fail_callback to return a value #458

decision-dev opened this issue Apr 28, 2024 · 0 comments

Comments

@decision-dev
Copy link

Things to check first

  • 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(<value>,  <type>)
except TypeCheckError as err:
   x = some_function(err, z)

with the much cleaner and more elegant:

x = check_type(<value>,  <type>,  typecheck_fail_callback= partial(some_function, arg=z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant