Detect if required string literal escapes are missing from a type
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by tracing mypy's semantic analysis for forward references and the handling of quoted versus unquoted type names. Check how class definitions and cyclic imports are represented, and account for the issue's note about type aliases. Done means reporting missing required string-literal escapes, initially within a single module and eventually across cyclic imports.
Written by the indexing model from the issue text.
Description
Mypy should complain about code that isn't using string literal escaped when they are required:
class A:
def (self) -> A: ... # Should be an error; string literal escape required
Initially we could only detect these cases within a single module. A more general solution would also detect string literal types needed due to cyclic imports.
A simple implementation idea:
- Tag each instance type with information on whether the type is quoted or not.
- During semantic analysis, if a type is unquoted but the definition line for the type/class is in the current file but at a later line number, complain.
- The definition line for a class is actually the line after the end of the class definition. Alternatively, treat classes that are currently being analyzed specially.
We also need deal with type aliases, but this isn't needed for the first iteration.
I think that somebody started working on this a while back, but I can't remember the details. Maybe there is an existing issue as well?
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
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.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100