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

Add require #132

Open
msto opened this issue Jun 6, 2024 · 1 comment
Open

Add require #132

msto opened this issue Jun 6, 2024 · 1 comment
Labels
good first issue Good for newcomers

Comments

@msto
Copy link
Contributor

msto commented Jun 6, 2024

assert should be avoided outside unit tests.

The Google style guide requires this:

Do not use assert statements in place of conditionals or validating preconditions. They must not be critical to the application logic. A litmus test would be that the assert could be removed without breaking the code. assert conditionals are not guaranteed to be evaluated. For pytest based tests, assert is okay and expected to verify expectations.

The primary reason to avoid assert statements is that they are intended for debugging and can be disabled.

Per slack discussion, it would be convenient to have a require() function in fgpyo that acts like assert but cannot be disabled.

def require(
    condition: bool,
    message: str | None = None,
    error: Exception = RequirementError,
) -> None:
    """
    Require a condition to be met.

    Args:
        condition: The test condition.
        message: The error message to report.
        error: The exception class to raise.

    Raises:
        `RequirementError`: if `condition` is False. (The `Exception` class raised may be overridden by the `error` argument.
    """
    ...
@msto msto added the good first issue Good for newcomers label Jun 6, 2024
@harsha-mangena
Copy link

Hey @msto, Can I pick this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants