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

PR: Catch Multiple Errors #4

Closed
KyleKing opened this issue Sep 24, 2022 · 4 comments · Fixed by #5
Closed

PR: Catch Multiple Errors #4

KyleKing opened this issue Sep 24, 2022 · 4 comments · Fixed by #5
Labels
enhancement New feature or request

Comments

@KyleKing
Copy link
Contributor

KyleKing commented Sep 24, 2022

Would you be open to a PR that catches multiple errors and prints them all at once?

I was thinking that instead of the raise AttributeError(), the errors could be collected and then raised at the end

abcmeta/abcmeta/__init__.py

Lines 157 to 187 in 4fef29b

# Make sure the derived class has implemented the abstract method.
if name not in cls.__dict__:
raise AttributeError(
"Derived class '{}' has not implemented '{}' method of the"
" parent class '{}'.".format(
cls.__name__, name, cls.__base__.__name__
)
)
derived_method = getattr(cls, name)
# Get methods signatures.
*obj_method_signature, obj_method_signature_str = _get_signature(obj)
*derived_method_signature, derived_method_signature_str = _get_signature(
derived_method
)
# Compare signatures.
diff = _compare_signatures(
obj_method_signature_str, derived_method_signature_str
)
# Raise signature error.
if diff:
diff_details = _compare_signatures_details(
obj_method_signature, derived_method_signature
)
raise AttributeError(
"Signature of the derived method is not the same as parent"
" class:\r\n{}".format(_prepare_text_to_raise(diff, diff_details))
)

Could be modified like this:

errors = []
for name, obj in vars(cls.__base__).items():
    ...
    if name not in cls.__dict__:
        errors.append(
            "Derived class '{}' has not implemented '{}' method of the"
            " parent class '{}'.".format(
                cls.__name__, name, cls.__base__.__name__
            )
        )
        continue
    ...
if errors:
    raise AttributeError("\n\n".join(errors))
@mortymacs
Copy link
Owner

Hi Kyle,

That's an excellent idea! 👍
Would you please send a PR, or I prepare it myself?

@KyleKing
Copy link
Contributor Author

Submitting now! Just adding a new test

@mortymacs
Copy link
Owner

Hi Kyle,

I just released the new version. Please check it and let me know if there is anything you need. :)

Cheers,
Mort

@KyleKing
Copy link
Contributor Author

KyleKing commented Sep 25, 2022

Perfect, thanks! The Windows support and error index are really nice additions

@mortymacs mortymacs added the enhancement New feature or request label Sep 30, 2022
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

Successfully merging a pull request may close this issue.

2 participants