astral-sh / astral-sh/ruff

RUF002 offers unrelated substitution for unicode quotation mark

Open
#3,977 10 comments 3 reactions 0 assignees View on GitHub
fixes
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
445

Description

With ruff 0.0.261, using the "RUF" rule, the following docstring:
```python
"""All the account’s items"""
```
produces the following error:

```
RUF002 [*] Docstring contains ambiguous unicode character `’` (did you mean ```?)
```

The Unicode character in the comment is U+2019 RIGHT SINGLE QUOTATION MARK which is drawn from upper right to lower left. The suggested substitution is the backtick character which is drawn from upper left to lower right - this character is not semantically related to the Unicode character.

This suggestion is automatically applied when `--fix` is specified, producing:
```python
"""All the account`s items"""
```

Is this to avoid messing with docstring quotes by not substituting the single quote character `'`? In that case I would suggest not making this Unicode character autofixable at all, rather than substituting an unrelated character.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the RUF002 diagnostic on the documented Python docstring with --fix, then inspect the RUF002 rule and its autofix behavior. Done means the rule no longer suggests or applies an unrelated replacement for U+2019 RIGHT SINGLE QUOTATION MARK, with coverage for the reported example.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.