Describe the Bug
from typing import *
def test() -> list[str]:
args: Optional[list[str]] = []
return args
It seems that when a variable is declared as Optional, Pyrefly doesn't pay attention to whether the initial assignation is None or a value and just assumes on the return args statement that args might be None even though no code path exists under which it could reach the return statement with a None value.
Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AqADroRmGGEbwGACgCUdALQA%2BOlAhwGAbU2UAuohF1jdVJTZxEdAPLEGEXOlRQt6zTob69dALx0tekYmlDAMAK6U6KbmcEHGIAA0IGQhYFCkhAy0UBQAxHQACqSp6XRoWHj4dADGjpBsEaj2joQi%2BQDKMDB0ABYMDMSWAPRDKRLphLxsQzDoQ5i41XBDtej1jc1zdGC8pgBuqNCo2LA1dRANlE0OUbh2N3Ct6GQMPY6KezCUcDe%2BdEIgADMhAAjAAmAEiLRfajfQLoMLoLg8PgwTCKTAQELVeyfP4Acgu6F4MHxImJDEUIQAjmEsWjFABrGCkRSoarVeBwAkAdzM6DJ6BAAF8kuzcTAAGLQGAUco4AgkcjCoA
(Only applicable for extension issues) IDE Information
No response
Describe the Bug
It seems that when a variable is declared as
Optional, Pyrefly doesn't pay attention to whether the initial assignation isNoneor a value and just assumes on thereturn argsstatement thatargsmight beNoneeven though no code path exists under which it could reach thereturnstatement with aNonevalue.Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AqADroRmGGEbwGACgCUdALQA%2BOlAhwGAbU2UAuohF1jdVJTZxEdAPLEGEXOlRQt6zTob69dALx0tekYmlDAMAK6U6KbmcEHGIAA0IGQhYFCkhAy0UBQAxHQACqSp6XRoWHj4dADGjpBsEaj2joQi%2BQDKMDB0ABYMDMSWAPRDKRLphLxsQzDoQ5i41XBDtej1jc1zdGC8pgBuqNCo2LA1dRANlE0OUbh2N3Ct6GQMPY6KezCUcDe%2BdEIgADMhAAjAAmAEiLRfajfQLoMLoLg8PgwTCKTAQELVeyfP4Acgu6F4MHxImJDEUIQAjmEsWjFABrGCkRSoarVeBwAkAdzM6DJ6BAAF8kuzcTAAGLQGAUco4AgkcjCoA
(Only applicable for extension issues) IDE Information
No response