Skip to content

Errors in multiline implicit string concatenation not properly suppressed #3188

Closed

Description

@rexledesma

Describe the Bug

When you write a # pyrefly: ignore comment above a multi-line implicit string concatenation, only the first error is covered, even though this is a single construct.

# lol.py                                                                                     
x = (                                                                                                     
    # pyrefly: ignore [bad-index]                                                                         
    f"{d['foo']}\n"
    f"{d['bar']}"
)

In pyrefly@0.60.0, this results in an error in pyrefly check, even though the LSP does not error:

❯ uv run pyrefly check lol.py
ERROR Cannot index into `Literal['str']` [bad-index]
 --> lol.py:6:8
  |
6 |     f"{d['bar']}"
  |        ^^^^^^^^
  |
  No matching overload found for function `str.__getitem__` called with arguments: (Literal['bar'])
  Possible overloads:
  (key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | Unknown | None], /) -> LiteralString [closest match]
  (key: SupportsIndex | slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | Unknown | None], /) -> str
 INFO 1 error (1 suppressed)

I would expect one of the following:

  • The multiline string is treated as a single construct,
  • When running uv run pyrefly suppress lol.py, each component of the multiline string receive their own suppressions. However, this does not happen.
❯ uv run pyrefly suppress lol.py

 INFO 1 error (1 suppressed)
 INFO Inserting error suppressions...
 INFO Finished suppressing errors in 1/1 files

❯ cat lol.py
─────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────
     │ File: lol.py
─────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ d = "str"
   2 │
   3 │ x = (
     │
   4 │     # pyrefly: ignore [bad-index]
   5 │     f"{d['foo']}\n"
   6 │     f"{d['bar']}"
   7 │ )
─────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions