PY-76629: Fix DjangoViewNameCompletionTest.testViewNameCompletionInMethods

There were two underlying problems in Kotlin code:
```
run { DjangoFQNamesProvider.ACCEPTS_VIEW_NAME.isNameMatches(this) } != null
```
returned true regardless of the result of `isNameMatches(this)` call.
As a result, we used to suggest Django view names for *all* functions called
"reverse", "redirect" or "reverse_lazy".

Secondly, in FQNamesProviderExtKt.isNameMatches:
```
return getQualifiedNames().any {
  return it.firstComponent == elementQualifiedName.firstComponent &&
         it.lastComponent == elementQualifiedName.lastComponent
}
```
always returned the result of comparison with the first qualified name, ignoring the rest
due to non-local return from the inline `any`.

Finally, DjangoUrlViewProvider.isReverseFunction expected a PyFunctionType as the type
of reverse/redirect/reverse_lazy, but since these functions have overloads in .pyi
stubs we started to infer a union type of PyFunctionTypes for them, breaking the reference
provider. In general, it's better to perform a name resolution instead of type inference
to detect a fully qualified name for a reference.

GitOrigin-RevId: 69949b1b0e65f00557536cf16127279a83ea4f9d
This commit is contained in:
Mikhail Golubev
2024-08-15 18:45:02 +02:00
committed by intellij-monorepo-bot
parent 20b2e20d26
commit d69f93c593

View File

@@ -32,7 +32,6 @@ fun FQNamesProvider.isNameMatches(qualifiedNameOwner: PyQualifiedNameOwner): Boo
// Relaxed check: package and name
val elementQualifiedName = QualifiedName.fromDottedString(qualifiedName)
return getQualifiedNames().any {
return it.firstComponent == elementQualifiedName.firstComponent &&
it.lastComponent == elementQualifiedName.lastComponent
it.firstComponent == elementQualifiedName.firstComponent && it.lastComponent == elementQualifiedName.lastComponent
}
}