Closed fabriziosalmi closed 5 months ago
6 or more obtained atm, here next challenges with examples on remaining pylint warnings across the project:
Each issue type is explained with examples and solutions:
Missing Timeout Argument for requests.get
:
requests.get
without a timeout can cause your program to hang indefinitely.import requests
response = requests.get('http://example.com', timeout=10)
Disallowed Names:
foo = 42 # Bad
user_age = 42 # Good
Broad Exception Catch:
Exception
.try:
# Code that might throw an exception
except ValueError:
# Handle ValueError
except TypeError:
# Handle TypeError
Line Too Long:
Example:
# Bad
print("This is a very long line that exceeds the maximum allowed length and should be broken down.")
# Good
print("This is a very long line that exceeds the maximum allowed length "
"and should be broken down.")
Consider Using .items()
for Dictionary Iteration:
.items()
to iterate over both keys and values.Example:
# Bad
for key in my_dict:
value = my_dict[key]
# Good
for key, value in my_dict.items():
pass
Unused Variables and Imports:
Example:
# Bad
import os
foo = 42
# Good
# Remove unused 'import os' and 'foo' if they are not used elsewhere.
No Member Error:
import textstat
score = textstat.flesch_reading_ease("This is a test.") # Ensure 'flesch_reading_ease' exists
Redefining Outer Scope Variables:
Example:
# Bad
config = {'key': 'value'}
def function():
config = {'other_key': 'other_value'}
# Good
config = {'key': 'value'}
def function():
local_config = {'other_key': 'other_value'}
Missing Function or Module Docstrings:
def add(a, b):
"""Add two numbers and return the result."""
return a + b
Logging Format Issues:
%
.Example:
import logging
logger = logging.getLogger(__name__)
# Bad
logger.info("User %s logged in", user.name)
# Good
logger.info("User %s logged in", user.name)
Unspecified Encoding in File Operations:
Example:
# Bad
with open('file.txt', 'r') as f:
content = f.read()
# Good
with open('file.txt', 'r', encoding='utf-8') as f:
content = f.read()
Too Many Local Variables or Statements:
Example:
# Bad
def process_data(data):
var1 = ...
var2 = ...
...
# many lines of code
# Good
def process_data(data):
processed_data = step_one(data)
results = step_two(processed_data)
return results
added GitHub action to get pylint feedback at push events
Working on pylint scores improvements :)