LupoA / lsdensities

Smeared spectral densities from lattice correlators
GNU General Public License v3.0
3 stars 0 forks source link

Returning true/false based on an `if` #34

Closed edbennett closed 5 months ago

edbennett commented 6 months ago

This is a pedantic issue, but there is usually not a reason to write something like

if some_condition_that_is_boolean:
    return True
else:
    return False

The reason: some_condition_that_is_boolean is already True or False, so you can return it directly:

return some_condition_that_is_boolean

Bam, your function is 3 lines shorter so there are 3 fewer lines of code to need to understand.

edbennett commented 5 months ago

Note that adding "SIM" to the ruff linting options will point this out to avoid reintroducing it.

nickforce989 commented 5 months ago

This have been solved by ruff.

edbennett commented 5 months ago

It's still present in src/lsdensities/InverseProblemWrapper.py. Add "SIM" to line 35 of pyproject.toml and then run pre-commit run --all and it will highlight it.

nickforce989 commented 5 months ago

Done.

edbennett commented 5 months ago

Fab; can you fix the other issues that SIM now highlights?

nickforce989 commented 5 months ago

It appears that no issues are detected.

edbennett commented 5 months ago

Weird, I see two issues on my machine.

$ pre-commit run --all
ruff.....................................................................Failed
- hook id: ruff
- exit code: 1

src/lsdensities/InverseProblemWrapper.py:675:17: SIM102 Use a single `if` statement instead of nested `if` statements
src/lsdensities/utils/rhoUtils.py:237:13: SIM113 Use `enumerate()` for index variable `indx` in `for` loop
Found 2 errors.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

ruff-format..............................................................Passed
check yaml...............................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
check toml...............................................................Passed
mixed line ending........................................................Passed
nickforce989 commented 5 months ago

Ok, now I get them too, and I solved it.