Skip to content

Commit 6981fca

Browse files
committed
Add script to remove overrid for python 3.11
1 parent 4da305e commit 6981fca

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

remove_override.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import re
3+
4+
BASE_DIR = "./openscada_lite" # Change if needed
5+
6+
for root, _, files in os.walk(BASE_DIR):
7+
for file in files:
8+
if file.endswith(".py"):
9+
path = os.path.join(root, file)
10+
with open(path, "r", encoding="utf-8") as f:
11+
content = f.read()
12+
13+
# Remove standalone @override decorator lines
14+
content = re.sub(r"^\s*@override\s*$\n?", "", content, flags=re.MULTILINE)
15+
16+
# Remove 'override' from typing imports but keep other imports
17+
def remove_override_from_import(match):
18+
imports = match.group(1).split(",")
19+
imports = [imp.strip() for imp in imports if imp.strip() != "override"]
20+
if not imports:
21+
return "" # remove entire line if nothing left
22+
return f"from typing import {', '.join(imports)}"
23+
24+
content = re.sub(
25+
r"^from\s+typing\s+import\s+([^\n]+)",
26+
remove_override_from_import,
27+
content,
28+
flags=re.MULTILINE
29+
)
30+
31+
with open(path, "w", encoding="utf-8") as f:
32+
f.write(content)
33+
34+
print(f"Processed {path}")
35+

0 commit comments

Comments
 (0)