Skip to content

Improve multiline reporting #15273

@ikonst

Description

@ikonst

Current multiline error/notice reporting is hacky, e.g.

mypy/mypy/messages.py

Lines 1161 to 1169 in c1fb57d

self.note("Superclass:", context, offset=ALIGN_OFFSET + OFFSET, code=code)
self.pretty_callable_or_overload(
original,
context,
offset=ALIGN_OFFSET + 2 * OFFSET,
add_class_or_static_decorator=INCLUDE_DECORATOR,
allow_dups=ALLOW_DUPS,
code=code,
)

Notice how

  • we call notice multiple times even as it relates to the same core issue
  • we pass allow_dups=True to suppress deduplication of, say, the same type
  • we mistakenly(?) dedup the "Superclass:" and "Subclass:" notices
  • by always doing allow_dups=False, we can effectively dedup when it would make sense

I think it'll be better if the extra lines could be part of the error, also reducing code duplication (we end up passing a lot of the same parameters multiple times). Is there a reason why we didn't? Is it a pattern elsewhere in the code?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions