Improve mypy --pretty output for (multiline) f-strings
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Error messages merely say the line number, which is not always accurate - e.g. for multiline strings it's merely the first or last line of the overall multiline string (depending on Python version). If it's a format string and there's dozens of {} elements embedded in it, maybe across hundreds of lines, it can be practically impossible to tell what mypy is referring to. e.g. here's the actual output from a current problem:
src.py:136: error: "str" has no attribute "expression" [attr-defined]
src.py:136: error: Item "str" of "Optional[str]" has no attribute "expression" [union-attr]
src.py:136: error: Item "None" of "Optional[str]" has no attribute "expression" [union-attr]
src.py:136: error: Item "float" of "Optional[float]" has no attribute "expression" [union-attr]
src.py:136: error: Item "None" of "Optional[float]" has no attribute "expression" [union-attr]
src.py:136: error: "float" has no attribute "expression" [attr-defined]
src.py:136: error: "bool" has no attribute "expression" [attr-defined]
src.py:136: error: "int" has no attribute "expression" [attr-defined]
The multiline string these are embedded in is nearly a hundred lines long and has dozens of embedded elements, almost all of which reference an espression attribute. I genuinely have no idea which ones these messages are referring to. If it at least told me the name of the variable (or whatever), I'd be able to narrow it down.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing mypy's --pretty diagnostic rendering for errors arising in multiline f-strings; compare the reported location with the embedded expression that triggered it. Done means pretty output identifies the relevant f-string expression or variable rather than only the overall string's line.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100