Skip to content

Unhelpful message with a very long tuple initializer #7977

@JukkaL

Description

@JukkaL

This program genenerates an unhelpful error message:

from typing import Tuple
t: Tuple[int, ...] = (
    1, 2, 3, 4, 5, 6, 7, 8, 9., 10, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
    30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
    3, 31, 32, 33, 34, 35, 36, 37, 3, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
    30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 4, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
    30, 31, 32, 33, 34, 234234, 36, 37, 38, 39, 40, 1, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
    57, 58, 59, 60, 61, 62, 63
)

This is the message:

t.py:3: error: Incompatible types in assignment (expression has type <tuple: 148 items>, variable has type "Tuple[int, ...]")

This is derived from a real example, where the type was Tuple[Type[x], ...] and the initializer contained a long tuple of type objects. Figuring out which type object is incompatible was tricky.

Some ideas about how to improve this:

  • Point to individual tuple items that are incompatible. For example: Tuple item 8 has type "float"; "int" expected (also point the error message to the relevant line/column).
  • If there are many incompatibilities, only show a fixed number of them and hide the remaining ones.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy