Skip to content

Tuple length checking doesn't work with tuple() constructor #2445

@xavdid

Description

@xavdid

I searched for other, similar issues, but none seemed to cover this exact case.

Environment data

  • Language Server version: 2022.2.1
  • OS and version: darwin arm64
  • Python version (and distribution if applicable, e.g. Anaconda): 3.10.0
  • python.analysis.indexing: null
  • python.analysis.typeCheckingMode: basic

Expected behaviour

An error should be raised if tuple() is assigned to a tuple type of defined length

Actual behaviour

No error is raised

Code Snippet / Additional information

from typing import Tuple
Point3D = Tuple[int, int, int]

t1: Point3D = 1, 2, 3  # correct no error
t2: Point3D = 1, 2, 3, 4  # correct error; Element size mismatch; expected 3 but received 4
t3: Point3D = () # correct error; Element size mismatch; expected 3 but received 0
t4: Point3D = tuple() # expected error, none thrown

Given that tuple() returns an empty tuple, I'd expect t3 and t4 to behave identically. But, only one throws an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions