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

🎨 Apply flake8 for code style #1019

Merged
merged 1 commit into from
Feb 19, 2024
Merged

🎨 Apply flake8 for code style #1019

merged 1 commit into from
Feb 19, 2024

Conversation

stevenbal
Copy link
Contributor

@stevenbal stevenbal commented Feb 12, 2024

Better late than never :)

@stevenbal stevenbal force-pushed the feature/add-flake8 branch 2 times, most recently from 86481a2 to 489d817 Compare February 12, 2024 13:50
@stevenbal stevenbal requested a review from alextreme February 12, 2024 13:51
@alextreme
Copy link
Member

I'm not really in favor about style enforcing with flake8, I don't think catching unused variables and ordering imports improves a codebase sufficiently that it's worthwhile to mandate it via CI. I think black is sufficient.

But I'm also not about enforcing my preferences, so if @Bartvaderkin and @pi-sigma are in favor we can merge this in

@pi-sigma
Copy link
Contributor

pi-sigma commented Feb 13, 2024

@alextreme I'm down with this. Looking at the files changed, there are quite a few superfluous variable assignments and unused imports being cleaned up, f-strings without anything interpolated being converted to regular strings etc.

I don't think this is merely about style. Whether lines should be 80 or 100 chars long is a matter of style and preference, but unused imports and variable assignments are just cluttering the namespace; no one would prefer to keep them if it was pointed out.

Other things are perhaps debatable. See the below comment about unused imports in __init__ files. Even in that case, however, I consider the result an improvement.

Comment on lines 745 to 747
log
for log in logs
if self.zaak1["identificatie"] in log.extra_data["message"]
Copy link
Contributor

@Bartvaderkin Bartvaderkin Feb 13, 2024

Choose a reason for hiding this comment

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

Maybe not the best example but I want to be able to use single letter variables in cases like this. (ok maybe not lowercase l but in general)

@@ -232,7 +230,7 @@ def get_absolute_url(self, category=None):
)

def has_cta_tag(self):
return "\[CTABUTTON\]" in self.content
return "\[CTABUTTON\]" in self.content # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this noqa?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to src/open_inwoner/pdc/tests/test_product.py:271:46: W605 invalid escape sequence '\]'

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what this is supposed to be: does it even need the backslashes or was this a remnant of a regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, but I didn't want to change the code without knowing whether it's still necessary

Copy link
Contributor

@Bartvaderkin Bartvaderkin left a comment

Choose a reason for hiding this comment

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

This would be good to add, especially for the unused imports.

The amount of noqa's seems a bit much, and there a some that feel weird (I marked some)

Removing the unused variable names as hard rule is debatable, especially in tests they can help a lot showing what certain factories are for (I marked some examples). If we really must have this rule then restore the missing information (put it in a comment or some field on the object)

Also I want to keep the option to use single letter variables, sometimes they are more readable then breaking the whole thing up in a black mess, so let's leave that up to code review instead of a dogmatic rule.

@stevenbal
Copy link
Contributor Author

@Bartvaderkin I agree, the main reason I added this was for the imports. I could add F841 (unused variables) and E741 (ambiguous/short variable names) to the ignore list.

@codecov-commenter
Copy link

Codecov Report

Attention: 113 lines in your changes are missing coverage. Please review.

Comparison is base (79332e4) 94.74% compared to head (99a4ec1) 94.78%.
Report is 9 commits behind head on develop.

Files Patch % Lines
src/open_inwoner/openzaak/clients.py 85.41% 48 Missing ⚠️
src/open_inwoner/openklant/clients.py 81.53% 24 Missing ⚠️
src/open_inwoner/cms/cases/views/status.py 78.84% 11 Missing ⚠️
src/open_inwoner/openzaak/notifications.py 69.69% 10 Missing ⚠️
src/open_inwoner/openzaak/zgw_imports.py 67.74% 10 Missing ⚠️
src/open_inwoner/openklant/wrap.py 77.77% 2 Missing ⚠️
src/open_inwoner/accounts/query.py 75.00% 1 Missing ⚠️
src/open_inwoner/accounts/signals.py 0.00% 1 Missing ⚠️
src/open_inwoner/cms/cases/views/mixins.py 92.30% 1 Missing ⚠️
src/open_inwoner/openklant/services.py 80.00% 1 Missing ⚠️
... and 4 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1019      +/-   ##
===========================================
+ Coverage    94.74%   94.78%   +0.04%     
===========================================
  Files          872      871       -1     
  Lines        30546    30518      -28     
===========================================
- Hits         28940    28926      -14     
+ Misses        1606     1592      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Bartvaderkin
Copy link
Contributor

@stevenbal Let's allow the short variables.

I'm ambivalent about the unused variables rule but we if use it then let's convert the useful names from the tests into a comment.

@stevenbal
Copy link
Contributor Author

I added the unused variables and short variables rules to the ignorelist

Copy link
Contributor

@Bartvaderkin Bartvaderkin left a comment

Choose a reason for hiding this comment

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

Cool, cleans up a lot.

Maybe pick a tactical time to merge as it will be a bit of a hassle for the open PR's and everybody needs to update their githooks.

Copy link
Member

@alextreme alextreme left a comment

Choose a reason for hiding this comment

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

Can be merged, preferably next monday / early next week

@stevenbal stevenbal merged commit ed038ce into develop Feb 19, 2024
17 checks passed
@stevenbal stevenbal deleted the feature/add-flake8 branch February 19, 2024 10:14
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.

5 participants