python / python/mypy

(🐞) Note reported on wrong line

Open
#13,245 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

c: str
a: range | object
a + (
    "".join(
        "" + 1
    )
)

test.py:3:1: error: Unsupported left operand type for + ("range")  [operator]
    a + (
    ^
test.py:3:1: error: Unsupported left operand type for + ("object")  [operator]
    a + (
    ^
test.py:5:14: error: Unsupported operand types for + ("str" and "int")  [operator]
            "" + 1
                 ^
test.py:5:14: note: Left operand is of type "range | object"

In this instance, this note is completely irrelevant and very confusing.
Left operand is of type "range | object"?

This is coming from checkexpr.check_op/MessageBuilder.warn_operand_was_from_union

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

Reproduce the diagnostic with the Python snippet in the issue, then inspect checkexpr.check_op and MessageBuilder.warn_operand_was_from_union to trace why the union note is attached to the inner expression. Done means the reported note is no longer irrelevant or is associated with the correct operand; add or update a regression test covering this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.