Skip to content

Commit 35b9ad4

Browse files
committed
fix: handle multiple import correctly
1 parent 4f84411 commit 35b9ad4

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/osw/core.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,17 @@ def _fetch_schema(
948948
# else:
949949
imports.append(import_stmt)
950950
# replace all occurrences with empty string
951-
content = content.replace(import_stmt, "")
951+
# make sure to use match line start and end since import pattern
952+
# may overlap partially, e.g.
953+
# from datetime import date
954+
# from datetime import date, datetime
955+
print("Replace import statement:", import_stmt)
956+
content = re.sub(
957+
r"^" + re.escape(import_stmt) + r"$",
958+
"",
959+
content,
960+
flags=re.MULTILINE,
961+
)
952962
# remove duplicate imports (done by isort later)
953963
imports = list(set(imports))
954964
# add imports to the beginning of the file

0 commit comments

Comments
 (0)