apertium/apertium-python

Get rid of type: ignore

Closed this issue · 12 comments

There are a lot of them that I don't think we need.

orgh0 commented

@sushain97 I'm working on this in a separate branch.
I've removed some of the comments but I'm not able to figure out what's wrong with the following function

def translate(self, text, mark_unknown=False, format=None, deformat='txt', reformat='txt'):
        # type: (Translator, str, bool, Optional[str], str, str) -> str
        if '%s-%s' % tuple(map(to_alpha3_code, [self.l1, self.l2])) in apertium.pairs:  # type: ignore
            pair = map(to_alpha3_code, [self.l1, self.l2])
        else:
            raise apertium.ModeNotInstalled()

        if pair is not None:
            l1, l2 = pair
            cmds = list(self._get_commands(l1, l2))
            unsafe_deformat, unsafe_reformat = self._get_format(format, deformat, reformat)
            deformater, reformater = self._validate_formatters(unsafe_deformat, unsafe_reformat)
            deformatted = self._get_deformat(str(deformater), text)
            output = execute(deformatted, cmds)
            result = self._get_reformat(str(reformater), output).strip()
            return result.decode()  # type: ignore

could you take a look ?

What's the error?

orgh0 commented
 vagrant@vagrant  apertium_linux  ~/Documents/apertium_code_base/apertium-python   typecheck-corrections ± mypy apertium --strict --any-exprs-report .mypy_coverage --ignore-missing-imports
apertium/translation/__init__.py:90: error: Not enough arguments for format string
apertium/translation/__init__.py:103: warning: Returning Any from function declared to return "str"
apertium/translation/__init__.py:103: error: "str" has no attribute "decode"; maybe "encode"?
orgh0 commented

90 and 103 are the lines with the ignore comment in them

If result is a str, then why are you calling .decode on it?

For L90, I suggest doing something like l1, l2 = map(to_alpha3_code, [self.l1, self.l2]) first.

orgh0 commented

@sushain97 L90 fixed :)

orgh0 commented

also, @sushain97

If result is a str, then why are you calling .decode on it?

type(result) = <class 'bytes'>
type(result.decode()) = <class 'str'>
orgh0 commented

@sushain97 Yes, that was the issue

Are there still type: ignore left that need to be removed?