[1.12] Regression in is None narrowing · Issue #18021 · python/mypy (original) (raw)

Regression in 1.12.

I'm not sure if this is deliberate or somehow got missed, but I thought aiohttp was in the mypy test suite, so should have been caught in the regression tests..

    def feed_data(
        self,
        data: bytes,
        SEP: Optional[_SEP] = None,
        *args: Any,
        **kwargs: Any,
    ) -> Tuple[List[Tuple[RawResponseMessage, StreamReader]], bool, bytes]:
        if SEP is None:
            SEP = b"\r\n" if DEBUG else b"\n"
        return super().feed_data(data, SEP, *args, **kwargs)
aiohttp/http_parser.py:684:40: error: Argument 2 to "feed_data" of "HttpParser"
has incompatible type "Literal[b'\\r\\n', b'\\n'] | None"; expected
"Literal[b'\\r\\n', b'\\n']"  [arg-type]
            return super().feed_data(data, SEP, *args, **kwargs)
                                           ^~~

The variable can never be None at this point, so there should be no error (as in 1.11 and previous releases).