Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type of dict[Any, Any] is inferred as dict[Unknown, Unknown] #1094

Open
acidnik opened this issue Feb 20, 2025 · 1 comment
Open

type of dict[Any, Any] is inferred as dict[Unknown, Unknown] #1094

acidnik opened this issue Feb 20, 2025 · 1 comment
Labels
type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules upstream bug a bug that also exists in pyright but has not been raised upstream

Comments

@acidnik
Copy link

acidnik commented Feb 20, 2025

Description

from typing import Any, reveal_type

def dispatch(data: dict[Any, Any] | list[Any] | Any):
    if isinstance(data, dict):
        reveal_type(data)  # data is dict[Any, Any] | dict[Unknown, Unknown]
    elif isinstance(data, list):
        reveal_type(data)  # same problem here: data is list[Any] | list[Unknown]

Playground:
https://basedpyright.com/?typeCheckingMode=all&reportAny=false&reportExplicitAny=false&reportUnusedParameter=false&code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCCKcANFCAKYBuFAhgDYD68CFAUBwCYXBSdIBnBLRgBjABYAKTiNoAuPklEwA2kVKFiAXSgAfKPUGr1O-eoCUctlBuZeg1AJi0UoitNll%2Byy9dv-KGgZmRHcZZ3M-GwpDewFHZ1cwzwMjX38A6jomFmSIoA

pyright (same problem):
https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCCKcAUCQCYCmwU5SAzggIYwDGAFgBTktMBctJKxgBtInAA0hYgF0oAHygAbBqPFzF4gJR8SUfZhoNU9GExStK3XlLrCdeg05CUAbpSZKA%2BvARWeZlqO%2BpQqRvQmZhb%2BNsqqDk7Obh7evjGBQA

expected result: type of data must be the one specified in argument type

@DetachHead
Copy link
Owner

Any and "Unknown" mean the exact same thing, the only difference is which diagnostics they trigger (more info). if i were making basedpyright from scratch i would never have bothered creating two separate representations of the exact same type.

my guess is the logic that removes redundant types from the union isn't correctly accounting for the fact that Any and Unknown are the same type.

kinda related: #71

@DetachHead DetachHead added type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules upstream bug a bug that also exists in pyright but has not been raised upstream labels Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type checking / linting issues relating to existing diagnostic rules or proposals for new diagnostic rules upstream bug a bug that also exists in pyright but has not been raised upstream
Projects
None yet
Development

No branches or pull requests

2 participants