Skip to content

Replace Python 2 print statements with print function calls - #235

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260731-050229-07bcefc3
Open

Replace Python 2 print statements with print function calls#235
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260731-050229-07bcefc3

Conversation

@sonarqube-agent

Copy link
Copy Markdown

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Why these issues? Prioritized all 5 MAJOR-severity python:PrintStatementUsage violations, which represent clear and deterministic automation targets affecting only two files. This focused scope maximizes code quality improvement while maintaining coherence across a single, well-defined issue type.

Converts 5 instances of deprecated Python 2-style print statements to Python 3-compatible print function calls across fortune.py and letters.py. This fixes MAJOR-severity SonarQube violations and ensures the code is compatible with Python 3, where the print statement syntax is no longer supported.

View Project in SonarCloud


Fixed Issues

python:PrintStatementUsage - Replace print statement by built-in function. • MAJORView issue

Location: sonar-scanner/src/python/fortune.py:90

Why is this an issue?

The print statement was removed in Python 3.0. The built-in function should be used instead.

What changed

Replaces the Python 2-style print statement print 'Usage: fortune.py <filename>' with the Python 3-compatible built-in function call print('Usage: fortune.py <filename>'), fixing the code smell about using the removed print statement syntax.

--- a/sonar-scanner/src/python/fortune.py
+++ b/sonar-scanner/src/python/fortune.py
@@ -90,1 +90,1 @@ if __name__ == '__main__':
-        print 'Usage: fortune.py <filename>'
+        print('Usage: fortune.py <filename>')
python:PrintStatementUsage - Replace print statement by built-in function. • MAJORView issue

Location: sonar-scanner/src/python/letters.py:150

Why is this an issue?

The print statement was removed in Python 3.0. The built-in function should be used instead.

What changed

This hunk converts the print statement on line 152 (print "Good question.") to a print() function call, replacing the deprecated Python 2 print statement with the built-in print function required in Python 3.

--- a/sonar-scanner/src/python/letters.py
+++ b/sonar-scanner/src/python/letters.py
@@ -152,1 +152,1 @@ def play_once():
-                print "Good question."
+                print("Good question.")
python:PrintStatementUsage - Replace print statement by built-in function. • MAJORView issue 1
python:PrintStatementUsage - Replace print statement by built-in function. • MAJORView issue 2

Location: sonar-scanner/src/python/letters.py:152

Why is this an issue?

The print statement was removed in Python 3.0. The built-in function should be used instead.

What changed

This hunk converts the print statement on line 154 (print "I don't understand the question.") to a print() function call, replacing the deprecated Python 2 print statement with the built-in print function required in Python 3. This also addresses the related print statement usage warning for the print "I don't un pattern detected at line 154.

--- a/sonar-scanner/src/python/letters.py
+++ b/sonar-scanner/src/python/letters.py
@@ -154,1 +154,1 @@ def play_once():
-            print "I don't understand the question."
+            print("I don't understand the question.")
python:PrintStatementUsage - Replace print statement by built-in function. • MAJORView issue

Location: sonar-scanner/src/python/letters.py:157

Why is this an issue?

The print statement was removed in Python 3.0. The built-in function should be used instead.

What changed

This hunk converts the print statement on line 150 (print 'That was a wasted question...') to a print() function call, fixing the Python 3 incompatibility where the print statement syntax is no longer supported.

--- a/sonar-scanner/src/python/letters.py
+++ b/sonar-scanner/src/python/letters.py
@@ -150,1 +150,1 @@ def play_once():
-                print 'That was a wasted question; it did not exclude any possibilities.'
+                print('That was a wasted question; it did not exclude any possibilities.')

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZ9rJA3GkdvHrJAQ8SGX for python:PrintStatementUsage rule
- AZ9rJA29kdvHrJAQ8SGR for python:PrintStatementUsage rule
- AZ9rJA29kdvHrJAQ8SGO for python:PrintStatementUsage rule
- AZ9rJA29kdvHrJAQ8SGP for python:PrintStatementUsage rule
- AZ9rJA29kdvHrJAQ8SGQ for python:PrintStatementUsage rule

Generated by SonarQube Agent (task: c35b2c1f-ecd0-4011-ad75-25c96d15e898)
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant