Skip to content

[1.16 regression] duplicated note for incompatible type #19240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ngnpope opened this issue Jun 5, 2025 · 1 comment · May be fixed by #19247
Open

[1.16 regression] duplicated note for incompatible type #19240

ngnpope opened this issue Jun 5, 2025 · 1 comment · May be fixed by #19247
Labels
bug mypy got something wrong

Comments

@ngnpope
Copy link
Contributor

ngnpope commented Jun 5, 2025

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
@ngnpope ngnpope added the bug mypy got something wrong label Jun 5, 2025
@ilevkivskyi
Copy link
Member

OK, I think I know what is going on:

  • First, as part of that PR we may visit r.h.s twice (which btw may be not really needed, so I may try to optimize it away).
  • Second, and probably more importantly, our logic for error de-duplication is flawed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants