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

Static analysis result in case of zip(typing.NamedTuple) is different from in case of zip(tuple) #1658

Closed
Kyurenpoto opened this issue Aug 10, 2021 · 2 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

@Kyurenpoto
Copy link

Environment data

Pylance v2021.8.0

  • Language Server version: 2021.8.0 (Pyright 1.1.159)
  • OS and version: Windows 10 (19043.1151)
  • Python version (& distribution if applicable, e.g. Anaconda): 3.9.5 (pipenv)

Expected behaviour

No error in following case when use normal tuple:

x = (["1"], ["2"], [3])
y = list(zip(*x))

for a, b, c in zip(*x):
    print(a, b, c) #1 2 3

And Pylance analyzes the type of variables:

image
image
image
image

Actual behaviour

Error occured:
Tuple size mismatch: expected 3 but received 1 Pylance(reportGeneralTypeIssues) [11, 5]

from typing import NamedTuple

class T(NamedTuple):
    a: list[str]
    b: list[str]
    c: list[int]

x = T(["1"], ["2"], [3])
y = list(zip(*x))

for a, b, c in zip(*x):
    print(a, b, c) #1 2 3

And Pylance analyzes the type of variables:

image
image
image
image

This is cleary false-positive behavior.

@erictraut
Copy link
Contributor

Thanks for reporting the issue. I've added support for unpacking of objects that derive from a known-length tuple. This includes named tuples. The change will be included in the next release of pylance.

@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 10, 2021
@heejaechang
Copy link
Contributor

fixed in 2021.8.1 release.

@heejaechang heejaechang removed the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Aug 11, 2021
@jakebailey jakebailey added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Aug 23, 2021
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

4 participants