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

Ternary operator in dataclass default value doesn't highlight properly #6583

Open
my1e5 opened this issue Oct 21, 2024 · 0 comments
Open

Ternary operator in dataclass default value doesn't highlight properly #6583

my1e5 opened this issue Oct 21, 2024 · 0 comments
Assignees
Labels
needs repro Issue has not been reproduced yet

Comments

@my1e5
Copy link

my1e5 commented Oct 21, 2024

Pylance version: v2024.10.101 (pre-release)
OS and version: Windows 10

MRE

Here is a simple example, the default value of x is dependent on the OS.

import os
from dataclasses import dataclass, field

FOO = 1
BAR = 2


@dataclass
class A:
    x: int = field(default=FOO if os.name == "nt" else BAR)

Expected behavior

I would expect both FOO and BAR to highlighted blue and hovering should show

(constant) FOO: Literal[1]

and

(constant) BAR: Literal[2]

Actual behavior

Image

Notice how BAR isn't highlighted in blue, it is white. And if I hover BAR it says

(function) BAR: Any

If I test this same MRE on a macOS machine, then the bug swaps around. FOO becomes white and (function) instead.

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants