Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARPY-2189 Represent Django views in the updated project level symbol table #2121

Merged
merged 2 commits into from
Nov 4, 2024

Conversation

guillaume-dequenne-sonarsource
Copy link
Contributor

@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource commented Nov 1, 2024

@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource force-pushed the SONARPY-2189 branch 7 times, most recently from 16137ac to 436dc9a Compare November 1, 2024 10:51
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource force-pushed the SONARPY-2189 branch 2 times, most recently from a43d63c to 31dc566 Compare November 1, 2024 11:25
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource changed the title SONARPY-2189 SONARPY-2189 Represent Django views in the updated project level symbol table Nov 1, 2024
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource force-pushed the SONARPY-2189 branch 4 times, most recently from d905db9 to d017d01 Compare November 1, 2024 12:55
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource marked this pull request as ready for review November 1, 2024 13:05
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource force-pushed the SONARPY-2189 branch 3 times, most recently from 952f2e5 to 849a3dd Compare November 1, 2024 15:33
.filter(symbol -> symbol.fullyQualifiedName() != null)
.ifPresent(symbol -> djangoViewsFQN.add(symbol.fullyQualifiedName()));
PythonType pythonType = viewArgument.expression().typeV2();
if (pythonType instanceof UnknownType.UnresolvedImportType unresolvedImportType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we will need to add FQN for other types (at least for ClassType) I suggest to introduce an interface like HasFullyQualifiedName, and implement it for the UnresolvedImportType and for the FunctionType. Then this if-else will be simplified

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, UnresolvedImportType does not have a fully qualified name, because we said fully qualified name is strictly the name where a type is defined, and not just a re-exported name. Because the type is unknown, it has an importPath instead, which I think is good to keep as a clearly distinct concept from fullyQualifiedName.

In this case, I think what is misleading is probably the fact that I kept djangoViewsFqns when it probably should be djangoViewsImportPaths (fullyQualifiedName being seen here as a more precise import path).

Wdyt?

If we agree on that, I can rename the variable for djangoViewsFqns. As for the HasFullyQualifiedName interface, I agree it will make sense when introduced for ClassType, though. I'd probably introduce it at the same time as ClassType however.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, UnresolvedImportType does not have a fully qualified name, because we said fully qualified name is strictly the name where a type is defined, and not just a re-exported name. Because the type is unknown, it has an importPath instead, which I think is good to keep as a clearly distinct concept from fullyQualifiedName.

In this case, I think what is misleading is probably the fact that I kept djangoViewsFqns when it probably should be djangoViewsImportPaths (fullyQualifiedName being seen here as a more precise import path).

Wdyt?

If we agree on that, I can rename the variable for djangoViewsFqns. As for the HasFullyQualifiedName interface, I agree it will make sense when introduced for ClassType, though. I'd probably introduce it at the same time as ClassType however.

def ambiguous(): ...
else:
def ambiguous(): ...
urlpatterns.append(path('bar', ambiguous, name='bar'))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: here is definition of the urlpatterns is missed which could confuse reading this test case

String content = """
from django.urls import conf
import views
urlpatterns = [conf.path('foo', views.foo, name='foo'), conf.path('baz')]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here urlpatterns is defined though? Are you referring to something else?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, I misread it, yes, here is ok

@@ -135,4 +138,8 @@ public PythonType owner() {
public TypeOrigin typeOrigin() {
return typeOrigin;
}

public String fullyQualifiedName() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now we have let's say two types having fqn (the UnresolvedImportType and the FunctionType and in nearest future we may want to add it to more types - I think it makes sense to introduce an interface like:

public interface HasFullyQualifiedName {
  String fullyQualifiedName();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the previous comment, UnresolvedImportType does not have a fqn.

We could have another interface that returns importPath (which would be the FQN for FunctionType and ClassType). I'm not yet sure about that though, as I'm afraid it could be misused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, left a couple of comments.
Also, for the moment we have its own way of construction of the FQN in the PythonTypeToDescriptorConverter, maybe it make sense to change it for the FunctionType by using new method in this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

sonarqube-next bot commented Nov 4, 2024

@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource merged commit 95e8e9b into MMF-3945 Nov 4, 2024
3 of 9 checks passed
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource deleted the SONARPY-2189 branch November 4, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants