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

Ignore handled exceptions in try blocks #1861

Open
MusicalNinjaDad opened this issue Jan 11, 2025 · 1 comment
Open

Ignore handled exceptions in try blocks #1861

MusicalNinjaDad opened this issue Jan 11, 2025 · 1 comment

Comments

@MusicalNinjaDad
Copy link

I have the following code which returns as attribute-error unless silenced:

    def __eq__(self, value: object) -> bool:
        """Dice are equal if they give the same probabilities."""
        try:
            return self.probabilities == value.probabilities # pytype: disable=attribute-error
        except AttributeError:
            return False

As handling attribute and type issues is a common case for try: ... except: blocks it would be great if pytype automatically ignored type errors which were specifically handled in the code.

@deborshi-web
Copy link

@MusicalNinjaDad

I hope it works

def eq(self, value: object) -> bool:
"""Dice are equal if they give the same probabilities."""
try:
return self.probabilities == value.probabilities # pytype: disable=attribute-error
except AttributeError:
return False

your code was not Indented

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

No branches or pull requests

2 participants