Skip to content

Flake8 showcase #5

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flake8/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 88
extend-ignore = E203, W503

16 changes: 16 additions & 0 deletions flake8/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os, sys # F401: sys imported but unused
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove unused imports for cleaner code.

The static analysis tools correctly identify that both os and sys imports remain unused in this file.

-import os, sys  # F401: sys imported but unused
+# Remove unused imports or use them in your code
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import os, sys # F401: sys imported but unused
# Remove unused imports or use them in your code
🧰 Tools
🪛 Ruff (0.12.2)

1-1: os imported but unused

Remove unused import

(F401)


1-1: sys imported but unused

Remove unused import

(F401)

🪛 Flake8 (7.2.0)

[error] 1-1: 'os' imported but unused

(F401)


[error] 1-1: 'sys' imported but unused

(F401)

🤖 Prompt for AI Agents
In flake8/example.py at line 1, both 'os' and 'sys' modules are imported but not
used anywhere in the file. Remove these unused import statements to clean up the
code and satisfy static analysis tools.


def my_function( x, y ):
print( "Result:",x+y ) # E201, E202, E231, E221
Comment on lines +3 to +4
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix function signature spacing and print statement formatting.

The function contains multiple spacing violations that flake8 catches.

-def my_function(  x, y ):
-  print(  "Result:",x+y )  # E201, E202, E231, E221
+def my_function(x, y):
+    print("Result:", x + y)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def my_function( x, y ):
print( "Result:",x+y ) # E201, E202, E231, E221
def my_function(x, y):
print("Result:", x + y)
🧰 Tools
🪛 Flake8 (7.2.0)

[error] 4-4: indentation is not a multiple of 4

(E111)

🤖 Prompt for AI Agents
In flake8/example.py around lines 3 to 4, fix the spacing issues in the function
signature by removing extra spaces before the parameters and after the opening
parenthesis. Also, adjust the print statement to have proper spacing after
commas and around operators to comply with flake8 rules.


class myclass: # N801: class name should use CapWords convention
def __init__(self):
self.value =42 # E225: missing whitespace around operator
Comment on lines +6 to +8
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Apply Python naming conventions and fix indentation.

The class violates PEP 8 naming conventions and has inconsistent indentation.

-class myclass:  # N801: class name should use CapWords convention
- def __init__(self):
-     self.value =42  # E225: missing whitespace around operator
+class MyClass:
+    def __init__(self):
+        self.value = 42
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class myclass: # N801: class name should use CapWords convention
def __init__(self):
self.value =42 # E225: missing whitespace around operator
class MyClass:
def __init__(self):
self.value = 42
🧰 Tools
🪛 Flake8 (7.2.0)

[error] 7-7: indentation is not a multiple of 4

(E111)


[error] 8-8: indentation is not a multiple of 4

(E111)

🤖 Prompt for AI Agents
In flake8/example.py around lines 6 to 8, rename the class to use CapWords
convention (e.g., MyClass) and fix the indentation to use consistent spaces
(typically 4 spaces per indentation level). Also, add a space around the
assignment operator in the __init__ method to comply with PEP 8.


def doSomething(self): # N802: function name should be snake_case
if( self.value>0 ):
print("Positive")
else:
print( "Not positive" )
Comment on lines +10 to +14
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix method naming, spacing, and indentation consistency.

The method has multiple violations including naming conventions and inconsistent formatting.

- def doSomething(self):  # N802: function name should be snake_case
-    if( self.value>0 ):
-         print("Positive")
-    else:
-         print( "Not positive" )
+    def do_something(self):
+        if self.value > 0:
+            print("Positive")
+        else:
+            print("Not positive")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def doSomething(self): # N802: function name should be snake_case
if( self.value>0 ):
print("Positive")
else:
print( "Not positive" )
def do_something(self):
if self.value > 0:
print("Positive")
else:
print("Not positive")
🧰 Tools
🪛 Flake8 (7.2.0)

[error] 10-10: indentation is not a multiple of 4

(E111)


[error] 12-12: indentation is not a multiple of 4

(E111)


[error] 12-12: over-indented

(E117)


[error] 14-14: indentation is not a multiple of 4

(E111)


[error] 14-14: over-indented

(E117)

🤖 Prompt for AI Agents
In flake8/example.py around lines 10 to 14, rename the method from doSomething
to do_something to follow snake_case naming conventions. Remove unnecessary
spaces inside parentheses and after keywords, and ensure consistent indentation
throughout the method. Adjust spacing around operators and after commas to
comply with PEP8 style guidelines.


my_function(1,2)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add proper spacing in function call.

The function call needs proper spacing after the comma.

-my_function(1,2)
+my_function(1, 2)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
my_function(1,2)
my_function(1, 2)
🤖 Prompt for AI Agents
In flake8/example.py at line 16, the function call my_function(1,2) lacks proper
spacing after the comma. Add a space after the comma so it reads my_function(1,
2) to comply with spacing conventions.