You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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..
Interestingly, we used to infer the correct union type before #17427, so this is perhaps not just a pre-existing issue that #17427 exposed but something more subtle.
@Dreamsorcerer could you please find a simple self-contained repro? (I guess there may be something special about aiohttp setup) because the above example works for me in a recent master.
@ilevkivskyi Sorry for the delay, been a slow month.
I broke it down to a minimal reproducer, then realised that it's almost exactly the same as the above example. After some more testing I've realised that the reveal_type() is fixing the example. Simply removing the first reveal_type() reproduces the issue again:
from typing import Literal
SEP = Literal["a", "b"]
class Base:
def feed_data(
self,
sep: SEP,
) -> int:
return 0
class C(Base):
def feed_data(
self,
sep: SEP | None = None,
) -> int:
if sep is None:
sep = "a" if int() else "b" # Union[Literal['a'], Literal['b']?]
reveal_type(sep) # None
# Incompatible type "Literal['a', 'b'] | None"; expected "Literal['a', 'b']"
return super().feed_data(sep)
Activity
[-]Regression in `is None` narrowing[/-][+][1.12] Regression in `is None` narrowing[/+]JukkaL commentedon Oct 23, 2024
This bisects to #17427. Here is a complete, slightly simplified reproducer:
Interestingly, we used to infer the correct union type before #17427, so this is perhaps not just a pre-existing issue that #17427 exposed but something more subtle.
cc @ilevkivskyi
Dreamsorcerer commentedon Oct 23, 2024
Appears mypy_primer did catch it, but there were probably too many changes there for someone to notice the legitimate regression.
JukkaL commentedon Oct 23, 2024
Yeah. I think the vast majority of new errors were legitimate.
Fix ternary union for literals (#18023)
Dreamsorcerer commentedon Dec 25, 2024
Not sure this was fully resolved. The linked fix is in 1.14, but the aiohttp regression is still present:
https://github.com/aio-libs/aiohttp/actions/runs/12496766030/job/34868785013?pr=10222
ilevkivskyi commentedon Dec 27, 2024
@Dreamsorcerer could you please find a simple self-contained repro? (I guess there may be something special about aiohttp setup) because the above example works for me in a recent master.
Dreamsorcerer commentedon Jan 26, 2025
@ilevkivskyi Sorry for the delay, been a slow month.
I broke it down to a minimal reproducer, then realised that it's almost exactly the same as the above example. After some more testing I've realised that the reveal_type() is fixing the example. Simply removing the first reveal_type() reproduces the issue again:
ilevkivskyi commentedon Jan 27, 2025
OK, nice, I have a fix, but it is too late, I will make a PR tomorrow.
ilevkivskyi commentedon Jan 27, 2025
@Dreamsorcerer here is the real fix #18545