pytype icon indicating copy to clipboard operation
pytype copied to clipboard

Ignore handled exceptions in `try` blocks

Open MusicalNinjaDad opened this issue 11 months ago • 1 comments

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.

MusicalNinjaDad avatar Jan 11 '25 10:01 MusicalNinjaDad

@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

deborshi-web avatar Jan 11 '25 15:01 deborshi-web

Hi, thank you for your report. Google is shifting its effort to a different approach for type checking apart from pytype, and we're not planning to put in any effort in the near future in pytype, so we'll close this issue. Please see the announcement here.

h-joo avatar Aug 20 '25 16:08 h-joo