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

A few refactoring if/elif/else construction #107

Closed
wants to merge 1 commit into from

Conversation

ivanov-dv
Copy link

No description provided.

Copy link

codecov bot commented Dec 21, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
drf_excel/renderers.py 75.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
drf_excel/fields.py 100.00% <100.00%> (ø)
drf_excel/renderers.py 86.74% <75.00%> (ø)

@FlipperPA
Copy link
Member

@ivanov-dv Thanks for the contribution. Can you give us some context on why this refactor would be necessary?

In looking at the logic, some conditions seem to just be creating unnecessary operations, such as the changes to line 92 and 94. If that if / elif block matches the first condition, why should the rest be evaluated for a value that can't be possible?

It is entirely possible I'm missing something too.

@ivanov-dv
Copy link
Author

@FlipperPA Thanks for the answer!

This refactoring is not necessary and does not affect the functionality or speed of the code. But if we use the if / elif / else construct, the function stops executing after return / raise and transfers control to the external code. In your example, the code will not execute lines 92 and 94 if the condition on line 90 is true.

I also used the source pylint, where this case is described.

I could also possibly be missing something. I would appreciate your comments.

@browniebroke
Copy link
Member

I don't really the point in this change to be honest, as you put it:

This refactoring is not necessary and does not affect the functionality or speed of the code

Because of that, I would vote in favour of status-quo (don't change it).

I also used the source pylint, where this case is described.

Sure, linters are useful but this rule is very subjective IMO, reminds me of this article from Trey Hunner which does a good job at explaining why "it depends".

@ivanov-dv
Copy link
Author

@browniebroke Thanks for the answer! I agree with you, this can be very subjective.

@ivanov-dv ivanov-dv closed this Dec 25, 2024
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.

3 participants