Pyright: Callable returns Literal, but pyright maps it to str

Created on 16 Apr 2020  路  2Comments  路  Source: microsoft/pyright

Describe the bug
See the code below. Pyright detects the type for users to be Dict[int, str] even though it's Dict[int, UserType].

To Reproduce

from typing import Callable, Dict
from typing_extensions import Literal

UserType = Literal["User", "Admin"]

def print_user_type(user_type: UserType):
    print(user_type)

def run(fn: Callable[[], Dict[int, UserType]]):
    users = fn()
    for user_id, user_type in users.items():
        print_user_type(user_type)

Expected behavior
No pyright issues in the code above.

addressed in next version bug

Most helpful comment

This is now fixed in version 1.1.33, which I just published.

All 2 comments

Thanks for the bug report. This will be fixed in the next published version of pyright.

This is now fixed in version 1.1.33, which I just published.

Was this page helpful?
0 / 5 - 0 ratings