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

Incorrect/misleading error message for zip #1705

Closed
ldorigo opened this issue Aug 21, 2021 · 5 comments
Closed

Incorrect/misleading error message for zip #1705

ldorigo opened this issue Aug 21, 2021 · 5 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@ldorigo
Copy link

ldorigo commented Aug 21, 2021

Issue Type: Bug

Consider the following three functions (I've tried to remove as much unnecessary code as possible):

def get_vocab_from_file(vocab_name: str) -> Iterator[str]:
    for line in ["test_1","test_2","test_3"]:
        yield line.strip()

def get_samples_from_vocab(
    vocab: List[str], amount: int, exclude: Optional[List[str]] = None
) -> List[str]:
    candidates: List[str]
    while True:
        candidates = random.sample(vocab, amount)
        if not exclude or not any([candidate in exclude for candidate in candidates]):
            break
    return candidates

def create_neg_samples_test_file(vocab_name: str, amount: int = 5000):
    test_name = vocab_name + "_neg_samples"
    
    vocab = get_vocab_from_file(vocab_name)
    endless_vocab = itertools.cycle(vocab)
    vocab_rightsize = more_itertools.take(amount, endless_vocab)

    random_pairs = zip(
            vocab_rightsize,
            get_samples_from_vocab(vocab, amount),
        )
    # ...

The above code is wrong: get_samples_from_vocab expects a List[str] as first argument, while I am giving it an Iterator[str]. But this is what pylance shows me:

image

If I hover random pairs, the error message is:

image

Fair enough. If I hover any other part of the expression to learn more, however, I get this:

image

Which doesn't make sense (List[str],List[str] is a perfectly valid signature for the arguments of zip).

It's only if I hover on vocab that I get the actual error that appears to be causing the other ones:

image

And indeed, if I fix it that problem, the other errors go away:

image

Extension version: 2021.8.3-pre.1
VS Code version: Code 1.59.1 (3866c3553be8b268c8a7f8c0482c0c0177aa8bfa, 2021-08-19T11:54:37.513Z)
OS version: Linux x64 5.10.56-1-lts
Restricted Mode: No

System Info
Item Value
CPUs AMD Ryzen 7 3700X 8-Core Processor (16 x 4226)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 3, 2, 2
Memory (System) 31.36GB (2.91GB free)
Process Argv --crash-reporter-id 66ea3ec9-05eb-4edd-8d35-34bbe6c1aba1
Screen Reader no
VM 0%
DESKTOP_SESSION plasma-i3
XDG_CURRENT_DESKTOP KDE
XDG_SESSION_DESKTOP KDE-i3
XDG_SESSION_TYPE x11
@erictraut
Copy link
Contributor

Could you include the diagnostic message that you're seeing from pylance?

Also, it would be helpful if you could provide a sample that is a self-contained and minimal repro case. The code above is incomplete and includes symbols that are not defined. For example, I can't tell where the local variable vocab is being assigned a value.

@ldorigo
Copy link
Author

ldorigo commented Aug 21, 2021

Sorry, I am still writing the issue. Vscode started posting issues directly on github instead of preparing them in preview mode so it got posted before I was done...

@ldorigo
Copy link
Author

ldorigo commented Aug 21, 2021

Is it good enough now? I tried removing anything that isn't related to the issue or that depends on external code, and added back the assignment for vocab that got lost on the way. Let me know if there are other problems.

@erictraut
Copy link
Contributor

Thanks for the bug report. I agree that this error message is confusing and unnecessary. I've modified the logic to eliminate it. This change will be in the next release.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Aug 21, 2021
@heejaechang
Copy link
Contributor

the fix is in 2021.8.3 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants