[red-knot] Too many diagnostics for subclasses of cyclic classes #14223
Labels
bug
Something isn't working
help wanted
Contributions especially welcome
red-knot
Multi-file analysis & type inference
Consider the following Python snippet:
If you save this snippet in a
bar.pyi
file and run red-knot over that file, red-knot currently emits four diagnostics:Ideally we'd emit the first two of those diagnostics, but not the third or the fourth. Although it's impossible to calculate an accurate MRO for any of these classes due to the cycle between
Foo
andBar
, emitting so many diagnostics as a result of a single error is undesirable. If we actually emitted these diagnostics on user code, it would be likely to confuse the user about where the issue actually is.Baz
andSpam
are cyclically defined, of course, and we do need to detect that cycle, as we do currently, or we'll try to calculate the MROs of these classes and fall into infinite recursion. I think what we're currently missing is that after detecting the cycle (or perhaps as part of detecting the cycle), we need to do some extra work somewhere to figure out which classes are actually involved in the cycle. Here it isFoo
andBar
; we should not emit diagnostics forBaz
andSpam
, since they are not directly involved in the cycle.The text was updated successfully, but these errors were encountered: