Open
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?