Skip to content

Pyfix#1314

Open
Oa8choo2 wants to merge 12 commits intomainfrom
pyfix
Open

Pyfix#1314
Oa8choo2 wants to merge 12 commits intomainfrom
pyfix

Conversation

@Oa8choo2
Copy link
Copy Markdown
Contributor

j2lint found some errors in some python files on the site.
These python files need to be fixed (or removed?).
Most seem to be python 2 (print as statement, python 3 expects print as function, this was implemented in 2006).
Several of them are duplicated such as:
./intro-HPC/examples/Running-jobs-with-input-output-data/file2.py
./mkdocs/site/HPC/examples/Running_jobs_with_input_output_data/file2.py

Oa8choo2 added 12 commits March 26, 2026 11:21
based on suggestions of ruff and pylint
tested on python 3.14.3
…micolons

  --> file3.py:36:7
   |
34 | scratch_dir = os.environ.get('VSC_SCRATCH')
35 | filename_p1 = scratch_dir + "/primes_1.txt"
36 | print "Output File: ", filename_p1
   |       ^^^^^^^^^^^^^^^
37 | f_out = open(filename_p1, 'w+')
38 | for i in range(1, 30000):
   |

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> file3.py:59:7
   |
57 | f_in=open(filename_p1, "r")
58 | f_out=open(filename_p2, "w")
59 | print "Input File: ", filename_p1
   |       ^^^^^^^^^^^^^^
60 | print "Output File: ", filename_p2
61 | in_lines=f_in.readlines()                                #reads it line by line
   |

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> file3.py:60:7
   |
58 | f_out=open(filename_p2, "w")
59 | print "Input File: ", filename_p1
60 | print "Output File: ", filename_p2
   |       ^^^^^^^^^^^^^^^
61 | in_lines=f_in.readlines()                                #reads it line by line
62 | for line in in_lines:
   |

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> file3.py:81:7
   |
79 | end_time = int(time.time())
80 | duration = end_time - start_time
81 | print "Duration = " + str(duration) + " seconds."
   |       ^^^^^^^^^^^^^
   |

Found 4 errors.

error: Failed to parse file3.py:36:7: Simple statements must be separated by newlines or semicolons
F401 [*] `sys` imported but unused
  --> file3.py:10:8
   |
 8 | """
 9 |
10 | import sys
   |        ^^^
11 | import random
12 | import datetime
   |
help: Remove unused import: `sys`

F401 [*] `datetime` imported but unused
  --> file3.py:12:8
   |
10 | import sys
11 | import random
12 | import datetime
   |        ^^^^^^^^
13 | import time
14 | import os
   |
help: Remove unused import: `datetime`

Found 2 errors.
[*] 2 fixable with the `--fix` option.
************* Module file3
file3.py:7:0: C0301: Line too long (112/100) (line-too-long)
file3.py:71:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:72:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:73:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:74:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:75:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:76:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:77:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:78:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
file3.py:79:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:80:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:81:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:82:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:83:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
file3.py:63:5: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
file3.py:64:6: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
file3.py:75:1: C0103: Constant name "tot" doesn't conform to UPPER_CASE naming style (invalid-name)
file3.py:63:5: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
file3.py:64:6: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)

------------------------------------------------------------------
Your code has been rated at 6.20/10 (previous run: 6.20/10, +0.00)

$ python3.14  file3.py
Output File: ./primes_1.txt
Traceback (most recent call last):
  File "/tmp/brol/file3.py", line 64, in <module>
    filename_p1 = scratch_dir + "/primes_1.txt"
                  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

$ python3.14  file3.py
Output File: ./primes_1.txt
Input File: ./primes_1.txt
Output File: ./primes_2.txt
Traceback (most recent call last):
  File "/tmp/brol/file3.py", line 88, in <module>
    tot += int(list_values[i])
           ~~~^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
using Ruff and pylint

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:15:8
   |
13 |     now = time.time()
14 |     st = datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S')
15 |     print str, st
   |           ^^^
16 |     return int(now)
   |

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:24:10
   |
22 |             return num
23 |         else:
24 |             print "Please enter an integer which is bigger as one."
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25 |             retries = retries - 1
26 |         if retries <= 0:
   |

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:31:7
   |
30 | # PRIMES
31 | print "This program calculates all primes between 1 and your upper limit."
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32 | num = ask_int('Enter your upper limit (>1): ')
33 | start_time = print_time("Start Time: ")
   |

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:34:7
   |
32 | num = ask_int('Enter your upper limit (>1): ')
33 | start_time = print_time("Start Time: ")
34 | print "[Prime#1] = 1"
   |       ^^^^^^^^^^^^^^^
35 | ctr = 1
36 | for n in range(2, int(num)):
   |

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:43:9
   |
41 |         # loop fell through without finding a factor
42 |         ctr += 1
43 |         print "[Prime#%i] = %i" % (ctr,n)
   |               ^^^^^^^^^^^^^^^^^
44 | end_time = print_time("End Time: ")
45 | duration = end_time - start_time
   |

invalid-syntax: Simple statements must be separated by newlines or semicolons
  --> mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:47:7
   |
45 | duration = end_time - start_time
46 | s = "Duration:  " + str(duration) + " seconds."
47 | print s
   |       ^
   |

Found 6 errors.
************* Module primes
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:15:2: E0001: Parsing failed: 'Missing parentheses in call to 'print'. Did you mean print(...)? (<unknown>, line 15)' (syntax-error)

---
pylint  mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py
************* Module primes
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:16:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:17:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:18:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:19:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:22:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:23:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:24:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:25:0: W0311: Bad indentation. Found 3 spaces, expected 12 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:26:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:27:0: W0311: Bad indentation. Found 3 spaces, expected 12 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:28:0: W0311: Bad indentation. Found 3 spaces, expected 12 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:29:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:30:0: W0311: Bad indentation. Found 3 spaces, expected 12 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:31:0: W0311: Bad indentation. Found 3 spaces, expected 12 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:40:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:41:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:42:0: W0311: Bad indentation. Found 3 spaces, expected 12 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:43:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:45:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:46:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:15:0: C0116: Missing function or method docstring (missing-function-docstring)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:15:15: W0622: Redefining built-in 'str' (redefined-builtin)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:21:0: C0116: Missing function or method docstring (missing-function-docstring)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:23:2: W0621: Redefining name 'num' from outer scope (line 35) (redefined-outer-name)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:24:2: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:38:0: C0103: Constant name "ctr" doesn't conform to UPPER_CASE naming style (invalid-name)

------------------------------------------------------------------
Your code has been rated at 1.88/10 (previous run: 1.88/10, +0.00)

************* Module primes
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:16:0: C0116: Missing function or method docstring (missing-function-docstring)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:16:15: W0622: Redefining built-in 'str' (redefined-builtin)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:23:0: C0116: Missing function or method docstring (missing-function-docstring)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:25:8: W0621: Redefining name 'num' from outer scope (line 38) (redefined-outer-name)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:26:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py:41:0: C0103: Constant name "ctr" doesn't conform to UPPER_CASE naming style (invalid-name)

------------------------------------------------------------------
Your code has been rated at 8.12/10 (previous run: 1.88/10, +6.25)

 pylint  mkdocs/docs/HPC/examples/Running_interactive_jobs/primes.py

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
 python message.py
/tmp/brol/message.py:19: SyntaxWarning: invalid escape sequence '\ '
  \   ^__^ \n\
  File "/tmp/brol/message.py", line 25
        print cowtxt
        ^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

$ ruff format message.py
error: Failed to parse message.py:25:8: Simple statements must be separated by newlines or semicolons

$ pylint
************* Module message
mkdocs/docs/HPC/examples/Running_interactive_jobs/message.py:25:2: E0001: Parsing failed: 'Missing parentheses in call to 'print'. Did you mean print(...)? (<unknown>, line 25)' (syntax-error)

************* Module message
message.py:14:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
message.py:15:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
message.py:16:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
message.py:17:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
message.py:18:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
message.py:19:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
message.py:28:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
message.py:34:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
message.py:36:0: W0311: Bad indentation. Found 2 spaces, expected 4 (bad-indentation)
message.py:22:11: W1401: Anomalous backslash in string: '\ '. String constant might be missing an r prefix. (anomalous-backslash-in-string)
message.py:23:11: W1401: Anomalous backslash in string: '\ '. String constant might be missing an r prefix. (anomalous-backslash-in-string)
message.py:23:18: W1401: Anomalous backslash in string: '\_'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
message.py:24:18: W1401: Anomalous backslash in string: '\ '. String constant might be missing an r prefix. (anomalous-backslash-in-string)
message.py:24:27: W1401: Anomalous backslash in string: '\/'. String constant might be missing an r prefix. (anomalous-backslash-in-string)
message.py:24:29: W1401: Anomalous backslash in string: '\ '. String constant might be missing an r prefix. (anomalous-backslash-in-string)
message.py:13:0: C0116: Missing function or method docstring (missing-function-docstring)
message.py:31:0: C0103: Constant name "cmd" doesn't conform to UPPER_CASE naming style (invalid-name)
message.py:32:0: C0103: Constant name "ret" doesn't conform to UPPER_CASE naming style (invalid-name)
message.py:11:0: W0611: Unused import sys (unused-import)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

F401 [*] `sys` imported but unused
  --> message.py:11:8
   |
10 | import subprocess
11 | import sys
   |        ^^^
12 |
13 | def print_cowsay(cowsay):
   |
help: Remove unused import: `sys`

Found 1 error.
[*] 1 fixable with the `--fix` option.
$ python fibo.py
  File "/tmp/brol/fibo.py", line 8
                print b,
                ^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

 ruff check  fibo.py
invalid-syntax: Simple statements must be separated by newlines or semicolons
 --> fibo.py:8:9
  |
6 |     a, b = 0, 1
7 |     while b < n:
8 |         print b,
  |               ^
9 |         a, b = b, a+b
  |

Found 1 error.

(brol) user@computer:/tmp/brol$ ruff check  fibo.py
All checks passed!
(brol) user@computer:/tmp/brol$ pylint  fibo.py
************* Module fibo
fibo.py:6:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
fibo.py:7:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
fibo.py:8:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
fibo.py:9:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
fibo.py:12:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
fibo.py:13:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
fibo.py:14:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
fibo.py:15:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
fibo.py:16:0: W0311: Bad indentation. Found 2 spaces, expected 8 (bad-indentation)
fibo.py:17:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
fibo.py:20:0: W0311: Bad indentation. Found 1 spaces, expected 4 (bad-indentation)
fibo.py:1:0: C0114: Missing module docstring (missing-module-docstring)
fibo.py:5:0: C0116: Missing function or method docstring (missing-function-docstring)
fibo.py:8:2: W0106: Expression "(print(b), )" is assigned to nothing (expression-not-assigned)
fibo.py:11:0: C0116: Missing function or method docstring (missing-function-docstring)

-----------------------------------
Your code has been rated at 0.00/10

(brol)  20 user@computer:/tmp/brol$ vi fibo.commit
(brol) user@computer:/tmp/brol$ ruff check --fix fibo.py
All checks passed!
(brol) user@computer:/tmp/brol$ ruff format fibo.py
1 file reformatted
(brol) user@computer:/tmp/brol$ pylint  fibo.py
************* Module fibo
fibo.py:1:0: C0114: Missing module docstring (missing-module-docstring)
fibo.py:6:0: C0116: Missing function or method docstring (missing-function-docstring)
fibo.py:9:8: W0106: Expression "(print(b), )" is assigned to nothing (expression-not-assigned)
fibo.py:13:0: C0116: Missing function or method docstring (missing-function-docstring)

------------------------------------------------------------------
Your code has been rated at 7.33/10 (previous run: 0.00/10, +7.33)
@Oa8choo2 Oa8choo2 requested a review from boegel April 27, 2026 07:18
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