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 context manager for Error collector #468

Open
phackstock opened this issue Jan 30, 2025 · 0 comments
Open

Add context manager for Error collector #468

phackstock opened this issue Jan 30, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@phackstock
Copy link
Contributor

phackstock commented Jan 30, 2025

Using a context manager for the ErrorCollector() class could help reduce boilerplate and make our code more readable.
We'd be going from:

errors = ErrorCollector()
for item in items:
    if item does not meet condition:
        errors.append(ValueError("Item does not meet condition")
    )        
if errors:
    raise ValueError(errors)

to:

with ErrorCollector():
    for item in items:
        if item does not meet condition:
            raise ValueError("Item does not meet condition")
@phackstock phackstock added the enhancement New feature or request label Jan 30, 2025
@phackstock phackstock self-assigned this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant