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-2336 Ensure ClassDescriptor and FunctionDescriptor fullyQualifiedName are not nullable #2157

Merged
merged 2 commits into from
Nov 19, 2024

Conversation

guillaume-dequenne-sonarsource
Copy link
Contributor

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

SONARPY-2339

Following this PR, there are possible null arguments to ClassDescriptor#fullQualifiedName and FunctionDescriptor#fullQualifiedName in DescriptorUtils. These methods are no longer used in production code, and are only used in tests (mostly in ProjectLevelSymbolTableTest through ProjectLevelSymbolTable#from). SONARPY-2346 has been created to handle this.

@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource force-pushed the SONARPY-2336 branch 8 times, most recently from 50375af to 8beb3a7 Compare November 15, 2024 11:57
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource changed the title SONARPY-2339 tmp SONARPY-2336 Ensure ClassDescriptor and FunctionDescriptor fullyQualifiedName are not nullable Nov 15, 2024
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource marked this pull request as ready for review November 15, 2024 12:16
Copy link
Contributor

@thomas-serre-sonarsource thomas-serre-sonarsource left a comment

Choose a reason for hiding this comment

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

LGTM, great work 💪 !

I left many minor comments, and I think it is worth it to have a second round of review.

On the JIRA side, it looks a bit unclear to me. In my opinion you are tackling 3 tickets in this PR :

  • SONARPY-2336 as written in the PR title
  • SONARPY-2339 as commented in the PR
  • SONARPY-???? which does not exist and is meant to convert ***TypeTest to V2 (see comments in the review for a clearer explanation).

I'm okay with tackling several tickets in the same PR, but I'm unsure if the jira automation will work in this case, and I would prefer to see the 3 jira tickets in the title of the PR. It could be worth it to settle this so the development process covers this case.

Comment on lines 123 to 135
private AmbiguousDescriptor lastAmbiguousDescriptor(String... code) {
Symbol ambiguousSymbol = lastSymbolFromDef(code);
if (!(ambiguousSymbol instanceof AmbiguousSymbol)) {
Name name = lastName(code);
PythonType pythonType = name.typeV2();
if (!(pythonType instanceof UnionType unionType)) {
throw new AssertionError("Symbol is not ambiguous.");
}
AmbiguousDescriptor ambiguousDescriptor = (AmbiguousDescriptor) descriptor(ambiguousSymbol);
assertThat(ambiguousDescriptor.name()).isEqualTo(ambiguousSymbol.name());
assertThat(ambiguousDescriptor.fullyQualifiedName()).isEqualTo(ambiguousSymbol.fullyQualifiedName());
SymbolV2 symbol = name.symbolV2();
PythonTypeToDescriptorConverter converter = new PythonTypeToDescriptorConverter();
AmbiguousDescriptor ambiguousDescriptor = (AmbiguousDescriptor) converter.convert("my_package.mod", symbol, Set.of(unionType));
assertThat(ambiguousDescriptor.name()).isEqualTo(name.name());
assertThat(ambiguousDescriptor.fullyQualifiedName()).isEqualTo("my_package.mod." + symbol.name());
return ambiguousDescriptor;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh okay, you have converted those tests to V2! It took me quite long to understand why those tests have been impacted by your changes :-)

I think this is outside the scope of the current ticket. I suggest either updating the ticket description to note that you did this also in this PR or creating another ticket that you will link to this PR.
Usually, I would prefer to have different PRs/tickets so it is easier to review but since you have it already there, I would suggest to keep it like this!

Comment on lines +94 to +106
@Test
void multipleClassSymbolNotAmbiguous() {
ClassDescriptor classDescriptor = lastClassDescriptor(
"""
class A: ...
class A: ...
"""
);
assertThat(classDescriptor.name()).isEqualTo("A");
assertThat(classDescriptor.fullyQualifiedName()).isEqualTo("my_package.mod.A");
assertDescriptorToProtobuf(classDescriptor);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice that you moved this test here 👍

@guillaume-dequenne-sonarsource
Copy link
Contributor Author

guillaume-dequenne-sonarsource commented Nov 19, 2024

LGTM, great work 💪 !

I left many minor comments, and I think it is worth it to have a second round of review.

On the JIRA side, it looks a bit unclear to me. In my opinion you are tackling 3 tickets in this PR :

  • SONARPY-2336 as written in the PR title
  • SONARPY-2339 as commented in the PR
  • SONARPY-???? which does not exist and is meant to convert ***TypeTest to V2 (see comments in the review for a clearer explanation).

I'm okay with tackling several tickets in the same PR, but I'm unsure if the jira automation will work in this case, and I would prefer to see the 3 jira tickets in the title of the PR. It could be worth it to settle this so the development process covers this case.

I think the 3rd ticket you're referring to matches SONARPY-2346. I'm tackling a small part of it here because it's needed to repair the otherwise broken tests on ClassDescriptor otherwise. I probably should have squashed the 3rd commit into the second one (I believe I simply forgot to do it...).

When dealing with multiple tickets in a single PR, I personally don't like having them all in the PR title (I tend to think it feels bloated then). I tend to have the "main" ticket as a PR title, and the prerequisite as a separate commit. Indeed I don't think Jira automation works in this case. We can probably revisit this way of doing so that it works better with automation though.

Copy link
Contributor

@thomas-serre-sonarsource thomas-serre-sonarsource left a comment

Choose a reason for hiding this comment

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

LGTM!

Thanks for the explanations along the fixes 💪

I ll add a point to the weekly meeting to confirm and ensure everyone does the same thing when one PR is created for several tickets.

@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource merged commit 5e3324e into master Nov 19, 2024
9 of 10 checks passed
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