Skip to content

[1.16 regression] duplicated note for incompatible type #19240

Closed
@ngnpope

Description

@ngnpope

Bug Report

Note lines are being repeated when an error for an incompatible type is raised in certain cases.

Encountered when adding support for mypy v1.16 in typeddjango/django-stubs#2703

Bisected to #18847

To Reproduce

from django.db import models


class MyModel(models.Model):
    char1 = models.CharField(max_length=200, choices="test")

Expected Behavior

$ uvx --python=3.12 --with=django-stubs mypy==1.15 --strict bug.py
Installed 9 packages in 71ms
bug.py:5: error: Need type annotation for "char1"  [var-annotated]
bug.py:5: error: Argument "choices" to "CharField" has incompatible type "str"; expected "Iterable[tuple[Any, Any] | tuple[str, Iterable[tuple[Any, Any]]]] | Mapping[Any, Any] | type[Choices] | Callable[[], Iterable[tuple[Any, Any] | tuple[str, Iterable[tuple[Any, Any]]]] | Mapping[Any, Any]] | None"  [arg-type]
bug.py:5: note: Following member(s) of "str" have conflicts:
bug.py:5: note:     Expected:
bug.py:5: note:         def __iter__(self) -> Iterator[tuple[Any, Any] | tuple[str, Iterable[tuple[Any, Any]]]]
bug.py:5: note:     Got:
bug.py:5: note:         def __iter__(self) -> Iterator[str]
Found 2 errors in 1 file (checked 1 source file)

Actual Behavior

$ uvx --with=django-stubs mypy==1.16 --strict bug.py
bug.py:5: error: Need type annotation for "char1"  [var-annotated]
bug.py:5: error: Argument "choices" to "CharField" has incompatible type "str"; expected "Iterable[tuple[Any, Any] | tuple[str, Iterable[tuple[Any, Any]]]] | Mapping[Any, Any] | type[Choices] | Callable[[], Iterable[tuple[Any, Any] | tuple[str, Iterable[tuple[Any, Any]]]] | Mapping[Any, Any]] | None"  [arg-type]
bug.py:5: note: Following member(s) of "str" have conflicts:
bug.py:5: note:     Expected:
bug.py:5: note:         def __iter__(self) -> Iterator[tuple[Any, Any] | tuple[str, Iterable[tuple[Any, Any]]]]
bug.py:5: note:     Got:
bug.py:5: note:         def __iter__(self) -> Iterator[str]
bug.py:5: note:     Expected:
bug.py:5: note:         def __iter__(self) -> Iterator[tuple[Any, Any] | tuple[str, Iterable[tuple[Any, Any]]]]
bug.py:5: note:     Got:
bug.py:5: note:         def __iter__(self) -> Iterator[str]
Found 2 errors in 1 file (checked 1 source file)

Note that the last four "note" lines are repeated.

Your Environment

  • Mypy version used: 1.16
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: Python 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions