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

DRYify testing of validation errors #345

Closed
dylanhmorris opened this issue Jul 30, 2024 · 2 comments · Fixed by #351
Closed

DRYify testing of validation errors #345

dylanhmorris opened this issue Jul 30, 2024 · 2 comments · Fixed by #351
Labels
clean up Good code that could be better

Comments

@dylanhmorris
Copy link
Collaborator

We have this type of check/error message throughout the project. Could be good to write a function for it.

Originally posted by @damonbayer in #342 (comment)

@damonbayer damonbayer added the clean up Good code that could be better label Jul 30, 2024
@sbidari sbidari added this to the 🦆 Olorotitan milestone Jul 31, 2024
@sbidari
Copy link
Collaborator

sbidari commented Jul 31, 2024

What would this function look like given the error message for ValueError is different in each instance?

@damonbayer
Copy link
Collaborator

Something like

def helpful_type_assertion(value, expected_type, arg_name, context):
    if not isinstance(value, expected_type):
        raise TypeError(f"{arg_name} passed to {context} is expected to be {expected_type}. Got {value} with type {type(value)}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean up Good code that could be better
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants