python / python/mypy

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

Open
#15,805 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-type-context
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided example with mypy 1.4.1 and confirm the differing results for list multiplication. Trace the type checking of the two function calls and locate the relevant regression-test area in the repository. Done means the second call is accepted consistently with the parenthesized form, with a test covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.