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 1560 #1568

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from

Conversation

evidencebp
Copy link

addresses issue(s) #ISSUE 1560

Summary:

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.

Prerequisites:

  • Unless it is a documentation hotfix it should be merged against the dev branch
  • Branch is up-to-date with the branch to be merged with, i.e. dev
  • Build is successful
  • Code is cleaned up and formatted

The code was   
def dummy_gen():
        if 3 >4:
            yield {}

Clearly, the dummy_gen is not intended to reach the yield.
To clarify that, I changed the condition to False.
I still wonder why the function is needed.
Method prepare_measurements of class QuidelData  had 19 branches while Pylint recommends having at most 12.
I extracted the methods _prepare_device_id and to make the code more structured and solve that.
Function upload  had 68 statements while Pylint recommends having at most 50.
I added the cursor as a parameter to its external functions and moved them out.
 Function create_printer had 7 returns while Pylint recommends having at most 6.
The code checks for a list of options.
I removed some into a dictionary.
I also assigned the results into a variable and used a single return at the end of the function.
Static method extract_and_check_row of class CsvImporter had 14 returns while Pylint recommends having at most 6.
I extracted the functions _validate_geo_type  and _validate_geo_id to make the code more structured and solve that.
Method insert_dataset of class Database had 13 branches while Pylint recommends having at most 12.
I extracted the method _process_rows   to make the code more structured and solve that.
Function handle_meta had 65 statements while Pylint recommends having at most 50.
I extracted _process_signals to make the code more structured and solve that.
Function run had 24 branches while Pylint recommends having at most 12.
I extracted the debug_log function (print in debug mode) which is reused a few times.
I also extracted methods to make the code more structured and solve that.
Function update had 56 statements while Pylint recommends having at most 50.
I extracted _process_values to make the code more structured and solve that.
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.

Instead, I imported explicitly delta_epiweeks, add_epiweeks from delphi.utils.epiweek (line 85)
Catching Exception might hide unexpected exceptions (e.g., due to new code that will be added).
Static method _request of class Epidata  catches exception (line 134)

The try section is basically request.get
Exception was changed to requests.exceptions.JSONDecodeError                    , requests.exceptions.HTTPError   , requests.exceptions.Timeout                    , requests.exceptions.TooManyRedirects  , and requests.exceptions.RequestException

For details see
https://requests.readthedocs.io/en/latest/user/quickstart/#make-a-request
Same happened in static method _version_check (line 63).

Added there also AttributeError due to looking for ['info']['version']  in line 62.
Catching Exception might hide unexpected exceptions (e.g., due to new code that will be added).
Function update_from_data  catches exception (line 152)

The try section is cursor's execute
Exception was changed to mysql.connector.Error

For details see
https://dev.mysql.com/doc/connector-python/en/connector-python-api-errors-error.html
Made readable lines shorter
Made readable lines shorter.
Email body is more readable.
Made unreadable line shorter
Used a single assignment per variable, made query more readable
Made readable lines shorter
Made readable line shorter
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