Skip to content

Commit 7444875

Browse files
committed
Fix duplicate imports in __init__.py generation and resolve linter errors
Refactors `generate_init.py` to track previously imported names, ensuring that symbols exported by multiple modules are only imported once in the package `__init__.py`. This resolves F811 redefinition errors reported by linters. Changes: - `generate_init.py`: Added logic to filter out duplicate imports across modules and fixed the appending of import lines. - `pat2vec/__init__.py`: Regenerated file, removing duplicate imports for `COLUMNS_TO_DROP`, `SEARCH_TERM`, and `filter_annot_dataframe`. - `pat2vec/pat2vec_search/cogstack_search_methods.py`: Minor formatting fix for `field_list` assignment.
1 parent 2cfedb6 commit 7444875

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

generate_init.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,24 @@ def generate_init_file_content(package_path="pat2vec"):
7070
"",
7171
]
7272

73+
imported_names = set() # Keep track of names we've already imported.
74+
7375
for module, imports in sorted(module_to_imports.items()):
74-
if imports:
75-
sorted_imports = sorted(imports)
76+
unique_imports_for_module = []
77+
for name in sorted(imports):
78+
if name not in imported_names:
79+
unique_imports_for_module.append(name)
80+
imported_names.add(name)
81+
82+
if unique_imports_for_module:
7683
import_line = f"from {module} import ("
84+
output_lines.append(import_line)
7785

7886
wrapper = textwrap.TextWrapper(
7987
width=88, initial_indent=" ", subsequent_indent=" "
8088
)
81-
wrapped_imports = wrapper.fill(", ".join(sorted_imports))
89+
wrapped_imports = wrapper.fill(", ".join(unique_imports_for_module))
8290

83-
output_lines.append(import_line)
8491
output_lines.append(wrapped_imports)
8592
output_lines.append(")")
8693

pat2vec/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
search_diagnostic_orders,
6060
)
6161
from .pat2vec_get_methods.get_method_drugs import (
62-
COLUMNS_TO_DROP,
6362
DRUG_FIELDS,
6463
calculate_drug_features,
6564
create_drug_features_dataframe,
@@ -81,7 +80,6 @@
8180
get_current_pat_report_annotations,
8281
)
8382
from .pat2vec_get_methods.get_method_smoking import (
84-
SEARCH_TERM,
8583
SMOKING_FIELDS,
8684
calculate_smoking_features,
8785
get_smoking,
@@ -92,7 +90,6 @@
9290
get_current_pat_textual_obs_annotations,
9391
)
9492
from .pat2vec_get_methods.get_method_vte_status import (
95-
SEARCH_TERM,
9693
VTE_FIELDS,
9794
calculate_vte_features,
9895
get_vte_status,
@@ -399,7 +396,6 @@
399396
build_merged_bloods,
400397
build_merged_epr_mct_annot_df,
401398
build_merged_epr_mct_doc_df,
402-
filter_annot_dataframe,
403399
get_annots_joined_to_docs,
404400
join_docs_to_annots,
405401
merge_appointments_csv,

0 commit comments

Comments
 (0)