def fun1() -> str:
a:Literal['cosine', 'dot', 'euclidean', 'manhattan'] = 'cosine'
return a
def fun2() -> dict[str, str]:
a:Literal['cosine', 'dot', 'euclidean', 'manhattan'] = 'cosine'
b = {}
b[a] = 'test'
return b
Returned type dict[Literal['cosine', 'dot', 'euclidean', 'manhattan'], str] is not assignable to declared return type dict[str, str]
Describe the Bug
Consider this example:
fun2errors with:In
fun1the Literal type is considered a compatible 'subtype' of str asais always a str. Infun2it isn't. I would assumefun2to be ok as the returned dict just contains str keys.EDIT: Explicitly declaring
b: dict[str,str] = {}removes the error.Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AZCAxiVUUADropmGGDpgArugAUASjoBaAHx04DSoil0TdVIiEixUANoByAMa44rGHYA0dO5lwMPXmEUHKAhZDH87GgwAC1QGBnCAXToAXi8nF3Q3Y1NKGAZFSnQzKRk5BWV1LV1MCAcGG31KTybEo2LTc0tRcXsM1wifP087QODQmHCRqPRY%2BKTU9OcBnJNsReAAX1W6bBtUZLS7EX07HbyCot2QdxAyPLAoUkIGWigKAGI6AAVSB6e9BgcAQ6E50JA2IU4hBcOhCFIvgBlGAwOjReLEOCIAD02PuciehF4bGxMHQ2J8Djg2LBEKhDBh5IUvDMADdUNBUNhYKDYXSxAzYXRcMRBeg4PD0GQGNFYZpWaIXEK0hIQABmQgARgATKqpDZRNRKHBElJlFweHwYJhNLU8vUIArFnYIGx0Lxsuh3QxNHkAI6KCB5G0AaxgpE0qAcDngcGdAHdUEUzugQJtblGGQqAGLQGAUNBYPBEMhpoA
(Only applicable for extension issues) IDE Information
Pyrefly vscode extension version: 0.58.0