-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_override.py
More file actions
35 lines (28 loc) · 1.23 KB
/
remove_override.py
File metadata and controls
35 lines (28 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
import re
# Remove override when used in python3.11
BASE_DIR = "./openscada_lite" # Change if needed
for root, _, files in os.walk(BASE_DIR):
for file in files:
if file.endswith(".py"):
path = os.path.join(root, file)
with open(path, "r", encoding="utf-8") as f:
content = f.read()
# Remove standalone @override decorator lines
content = re.sub(r"^\s*@override\s*$\n?", "", content, flags=re.MULTILINE)
# Remove 'override' from typing imports but keep other imports
def remove_override_from_import(match):
imports = match.group(1).split(",")
imports = [imp.strip() for imp in imports if imp.strip() != "override"]
if not imports:
return "" # remove entire line if nothing left
return f"from typing import {', '.join(imports)}"
content = re.sub(
r"^from\s+typing\s+import\s+([^\n]+)",
remove_override_from_import,
content,
flags=re.MULTILINE,
)
with open(path, "w", encoding="utf-8") as f:
f.write(content)
print(f"Processed {path}")