Skip to content

Passing a list of tuples with an optional parameter works with 1 multiplier, not 2 #15805

Open
@rickwierenga

Description

@rickwierenga

Bug Report

(A clear and concise description of what the bug is.)

To Reproduce

from typing import List, Optional, Tuple

def take_list(the_list: List[Tuple[Optional[int], int]]):
  print(the_list)

take_list([(None, 1)]*12) # no error
take_list([(None, 1)]*12*8) # error
take_list([(None, 1)]*(12*8)) # no error

assert [(None, 1)]*12*8 == [(None, 1)]*(12*8) # passes

Expected Behavior

I expect the second function call to not raise an error.

Actual Behavior

The second function call does raise an error.

Your Environment

  • Mypy version used: mypy==1.4.1
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files):
# Global options:

[mypy]
warn_return_any = True
warn_unused_configs = True
check_untyped_defs = True

# Per-module options:

[mypy-usb.*]
ignore_missing_imports = True

[mypy-ot_api.*]
ignore_missing_imports = True

[mypy-pylibftdi.*]
ignore_missing_imports = True
  • Python version used: 3.10.12

Activity

changed the title [-]Passing a list of[/-] [+]Passing a list of tuples with an optional parameter works with 1 multiplier, not 2[/+] on Aug 2, 2023
SanjayManjunath

SanjayManjunath commented on Aug 6, 2023

@SanjayManjunath

Hey @rickwierenga, I found out that if a Sequence is used instead of List here, the covariance can be ensured since the issue is related to type variance in List. Can you check this out and let me know if it works. https://mypy-play.net/?mypy=latest&python=3.10&gist=be1b241ca37c34bc4ad3b216fc6fe5c4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-contextType context / bidirectional inference

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @JelleZijlstra@rickwierenga@SanjayManjunath

        Issue actions

          Passing a list of tuples with an optional parameter works with 1 multiplier, not 2 · Issue #15805 · python/mypy