Skip to content

Commit 5bf8a1f

Browse files
committed
ruff fix
1 parent f09ba47 commit 5bf8a1f

File tree

350 files changed

+935
-921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

350 files changed

+935
-921
lines changed

1 File handle/File handle binary/Deleting record in a binary file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pickle
2-
from typing import List, Tuple
2+
33

44
def delete_student_record() -> None:
55
"""
@@ -21,14 +21,14 @@ def delete_student_record() -> None:
2121
try:
2222
# Read existing student records from file
2323
with open("studrec.dat", "rb") as file:
24-
student_records: List[Tuple[int, ...]] = pickle.load(file)
24+
student_records: list[tuple[int, ...]] = pickle.load(file)
2525
print("Current student records:", student_records)
2626

2727
# Get roll number to delete
2828
roll_number: int = int(input("Enter the roll number to delete: "))
2929

3030
# Filter out the record with the specified roll number
31-
updated_records: List[Tuple[int, ...]] = [
31+
updated_records: list[tuple[int, ...]] = [
3232
record for record in student_records if record[0] != roll_number
3333
]
3434

1 File handle/File handle binary/File handle binary read (record in non list form).py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import pickle
3-
from typing import List, Tuple
3+
44

55
def read_binary_file() -> None:
66
"""
@@ -28,7 +28,7 @@ def read_binary_file() -> None:
2828
try:
2929
# Read student records
3030
with open(file_path, "rb") as file:
31-
student_records: List[Tuple[int, str, float]] = pickle.load(file)
31+
student_records: list[tuple[int, str, float]] = pickle.load(file)
3232

3333
# Print records in a formatted table
3434
print("\nStudent Records:")

1 File handle/File handle binary/Update a binary file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import pickle
3-
from typing import List, Tuple
3+
44

55
def initialize_file_if_not_exists(file_path: str) -> None:
66
"""
@@ -36,7 +36,7 @@ def update_student_record(file_path: str) -> None:
3636
try:
3737
with open(file_path, "rb+") as f:
3838
# Load existing records
39-
records: List[Tuple[int, str, float]] = pickle.load(f)
39+
records: list[tuple[int, str, float]] = pickle.load(f)
4040

4141
if not records:
4242
print("No records found in the file.")
@@ -90,7 +90,7 @@ def display_all_records(file_path: str) -> None:
9090

9191
try:
9292
with open(file_path, "rb") as f:
93-
records: List[Tuple[int, str, float]] = pickle.load(f)
93+
records: list[tuple[int, str, float]] = pickle.load(f)
9494

9595
if not records:
9696
print("No records found in the file.")

1 File handle/File handle binary/Update a binary file2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import pickle
3-
from typing import List, Tuple
3+
44

55
def initialize_file_if_not_exists(file_path: str) -> None:
66
"""
@@ -36,7 +36,7 @@ def update_student_record(file_path: str) -> None:
3636
try:
3737
with open(file_path, "rb+") as f:
3838
# Load existing records
39-
records: List[Tuple[int, str, int]] = pickle.load(f)
39+
records: list[tuple[int, str, int]] = pickle.load(f)
4040

4141
if not records:
4242
print("No records found in the file.")

1 File handle/File handle binary/question 1 (elegible for remedial, top marks).py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import pickle
3-
from typing import List, Tuple
3+
44

55
def initialize_file_if_not_exists(file_path: str) -> None:
66
"""
@@ -32,7 +32,7 @@ def write_sample_data(file_path: str) -> None:
3232
Args:
3333
file_path (str): Path to the file to write data to.
3434
"""
35-
sample_data: List[Tuple[int, str, float]] = [
35+
sample_data: list[tuple[int, str, float]] = [
3636
(1, "Ramya", 30.0),
3737
(2, "Vaishnavi", 60.0),
3838
(3, "Anuya", 40.0),
@@ -58,7 +58,7 @@ def count_remedial_students(file_path: str) -> None:
5858

5959
try:
6060
with open(file_path, "rb") as file:
61-
students: List[Tuple[int, str, float]] = pickle.load(file)
61+
students: list[tuple[int, str, float]] = pickle.load(file)
6262

6363
remedial_students = [student for student in students if student[2] < 40.0]
6464

@@ -84,7 +84,7 @@ def count_top_scorers(file_path: str) -> None:
8484

8585
try:
8686
with open(file_path, "rb") as file:
87-
students: List[Tuple[int, str, float]] = pickle.load(file)
87+
students: list[tuple[int, str, float]] = pickle.load(file)
8888

8989
if not students:
9090
print("No student records found.")
@@ -115,7 +115,7 @@ def display_all_students(file_path: str) -> None:
115115

116116
try:
117117
with open(file_path, "rb") as file:
118-
students: List[Tuple[int, str, float]] = pickle.load(file)
118+
students: list[tuple[int, str, float]] = pickle.load(file)
119119

120120
print("\nAll student records:")
121121
print(f"{'ROLL':<8}{'NAME':<15}{'PERCENTAGE':<12}")

1 File handle/File handle binary/search record in binary file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import pickle
3-
from typing import List, Tuple
3+
44

55
def initialize_file_if_not_exists(file_path: str) -> None:
66
"""
@@ -35,7 +35,7 @@ def search_student_record(file_path: str) -> None:
3535

3636
try:
3737
with open(file_path, "rb") as f:
38-
records: List[Tuple[int, str, float]] = pickle.load(f)
38+
records: list[tuple[int, str, float]] = pickle.load(f)
3939

4040
if not records:
4141
print("No records found in the file.")

1 File handle/File handle text/counter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict
1+
22

33
class TextCounter:
44
"""
@@ -56,7 +56,7 @@ def _read_content(self, content: str, is_file_path: bool) -> str:
5656
UnicodeDecodeError: If the file cannot be decoded properly
5757
"""
5858
if is_file_path:
59-
with open(content, 'r', encoding='utf-8') as file:
59+
with open(content, encoding='utf-8') as file:
6060
return file.read()
6161
return content
6262

@@ -103,7 +103,7 @@ def get_total(self) -> int:
103103
self.count_digits +
104104
self.count_special)
105105

106-
def get_stats(self) -> Dict[str, int]:
106+
def get_stats(self) -> dict[str, int]:
107107
"""
108108
Return detailed character statistics.
109109

1 File handle/File handle text/file handle 12 length of line in text file.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import os
22
import sys
33
import time
4-
from typing import NoReturn, List, Tuple
4+
from typing import NoReturn
55

66

7-
def _get_invalid_filename_chars() -> Tuple[str, ...]:
7+
def _get_invalid_filename_chars() -> tuple[str, ...]:
88
"""Return a tuple of invalid filename characters for the current OS."""
99
if sys.platform.startswith('win'):
1010
return ('\\', '/', ':', '*', '?', '"', '<', '>', '|')
1111
else: # Linux/macOS
1212
return ('/',)
1313

1414

15-
def is_valid_filename(filename: str) -> Tuple[bool, str]:
15+
def is_valid_filename(filename: str) -> tuple[bool, str]:
1616
"""
1717
Validate if a filename is valid for the current operating system.
1818
@@ -98,13 +98,13 @@ def print_short_lines(file_name: str) -> None:
9898
return
9999

100100
try:
101-
with open(file_name, "r", encoding="utf-8") as file:
102-
lines: List[str] = file.readlines()
101+
with open(file_name, encoding="utf-8") as file:
102+
lines: list[str] = file.readlines()
103103
if not lines:
104104
print(f"Info: File '{file_name}' is empty.")
105105
return
106106

107-
short_lines: List[str] = [line for line in lines if len(line.rstrip('\n')) < 50]
107+
short_lines: list[str] = [line for line in lines if len(line.rstrip('\n')) < 50]
108108

109109
if not short_lines:
110110
print("No lines with length < 50 characters (excluding newline).")

1 File handle/File handle text/input,output and error streams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def read_and_print_file(file_path: str) -> None:
2121
"""
2222
try:
2323
# Open file in read mode with explicit UTF-8 encoding
24-
with open(file_path, mode='r', encoding='utf-8') as file:
24+
with open(file_path, encoding='utf-8') as file:
2525
# Read and print lines in chunks for better memory efficiency
2626
for line in file:
2727
sys.stdout.write(line)

1 File handle/File handle text/question 2.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from typing import List, Tuple
21

32

4-
def display_short_words(file_path: str) -> Tuple[List[str], int]:
3+
def display_short_words(file_path: str) -> tuple[list[str], int]:
54
"""
65
Read a text file and extract words with fewer than 4 characters.
76
@@ -25,14 +24,14 @@ def display_short_words(file_path: str) -> Tuple[List[str], int]:
2524
OSError: For other OS-related errors (e.g., invalid path)
2625
"""
2726
# Read entire file content
28-
with open(file_path, 'r', encoding='utf-8') as file:
27+
with open(file_path, encoding='utf-8') as file:
2928
content: str = file.read()
3029

3130
# Split content into words (handles multiple whitespace characters)
32-
words: List[str] = content.split()
31+
words: list[str] = content.split()
3332

3433
# Filter words with length < 4 using a generator expression for memory efficiency
35-
short_words: List[str] = [word for word in words if len(word) < 4]
34+
short_words: list[str] = [word for word in words if len(word) < 4]
3635

3736
return short_words, len(short_words)
3837

0 commit comments

Comments
 (0)