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

Pylint alerts corrections as part of an intervention experiment 1230 #1231

Open
wants to merge 87 commits into
base: master
Choose a base branch
from

Conversation

evidencebp
Copy link

Makes the interventions describe in intervention issue.
The experiment is described here.

Each intervention was done in a dedicated commit with a message explaining it.

Replace if with direct assignment of the condition into the output variable
Function write_agenda had 56 statements while Pylint recommends having at most 50.
I extracted the methods check_agenda_file, get_valid_date, and get_valid_time to make the code more structured and solve that.
Function hangman had 67 statements while Pylint recommends having at most 50.
I extracted methods to make the code more structured and solve that.
Many returns make the code more complex. Added a score variable in the first case, merged the conditions in the second.
Method organise of class File_Organise had 6 nested-blocks while Pylint recommends having at most 5.
I extracted orgnise_directory to make the code more structured and solve that.
Simplified the code by replacing the if in direct assignment of the condition to the result variable.
Catching BaseException might hide unexpected exceptions (e.g., due to new code that will be added).
Method get_data of class Memory  catches BaseException (line 61)

The try section is

return self.data[key]
BaseException was changed to AttributeError (if there is no member data) and KeyError(if the key is not in data)

For details see
https://docs.python.org/3/library/exceptions.html#KeyError
Removed unneeded parentheses
Function move had 13 branches while Pylint recommends having at most 12.
I extracted methods for the long enough user choices to make the code more structured and solve that.
Catching Exception might hide unexpected exceptions (e.g., due to new code that will be added).
Function fruit_nutrition  catches Exception (line 59)

Exception was changed to ValueError (e.g., in converting age to a number), KeyError (e.g., nutritions['sugar'] if there is no key 'sugar')

For details see
https://docs.python.org/3/library/exceptions.html#ValueError
https://docs.python.org/3/library/exceptions.html#KeyError
The condition had many expressions that made it unclear.
Instead, there is a dictionary for winning moves, simplifying and clarifying the condition.
Wildcard imports (import *) make it harder to understand what is imported from where.
Removing it is also a defensive programming act,
 lowering the probability of collisions due to future new imports or objects.
Catching Exception might hide unexpected exceptions (e.g., due to new code that will be added).
Method _get_data of class TasteDive  catches Exception (line 139)

The try section gets a request, formats as json and looks up properties.

Exception was changed to requests.RequestException, KeyError, ValueError, json.JSONDecodeError

For details see
https://docs.python.org/3/library/exceptions.html
https://requests.readthedocs.io/en/latest/_modules/requests/exceptions/
https://docs.python.org/3/library/json.html
The if is equivalent to the condition, so it can be removed
Function helloworld had 18 branches while Pylint recommends having at most 12.
I extracted methods to make the code more structured and solve that.
Function main had 20 branches while Pylint recommends having at most 12.
I extracted methods to make the code more structured and solve that.
"Return output", in the try section, cannot raise exceptions (output was already computed).
The exception handling section will not be reached so it is better to remove it.
The return value is the Boolean of the condition so the if can be removed.
Catching Exception might hide unexpected exceptions (e.g., due to new code that will be added).
The code catches BaseException (line 23)

The try section mainly imports and change a directory

Exception was changed to ImportError, OSError

For details see
https://docs.python.org/3/library/exceptions.html#ImportError, https://docs.python.org/3/library/exceptions.html#OSError
Removed unneeded parentheses
Function flightradar had 6 nested-blocks while Pylint recommends having at most 5.
I extracted check_flight_between_destinations to make the code more structured and solve that.
Function main had 14 branches while Pylint recommends having at most 12.
I extracted methods to make the code more structured and solve that.
The ifs are not needed. It is simpler to return the condition directly.
Function expression_checker had 23 branches while Pylint recommends having at most 12.
Now there are functions for contains_invalid_characters, check_character_progression, and check_bracket_pairs
Method hexToAssembly of class MipsConverter had 63 statements while Pylint recommends having at most 50.
]Method assemblyToHex of class MipsConverter had 114 statements.
I extracted methods for handling types in various activities to make the code more structured and solve that.
made long line more readable
made long lines more readable
 made a long line more readable
made long line more readable
made long line more readable
made long line more readable
made long line more readable
made long line more readable
made long line more readable
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.

1 participant