Skip to content

Refactor: Replace wildcard imports with explicit imports in integration test files#3513

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/refactor-wildcard-imports-another-one
Draft

Refactor: Replace wildcard imports with explicit imports in integration test files#3513
Copilot wants to merge 3 commits intomasterfrom
copilot/refactor-wildcard-imports-another-one

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

Generic request

  • PR name follows the pattern #1234 – issue name
  • branch name does not contain '#'
  • base branch (master or release/xx) is correct
  • PR is linked with the issue
  • task status changed to "Code review"
  • code follows product standards
  • regression tests updated

Optional

  • unit-tests written
  • documentation updated

Description

Replace from env_indigo import * with explicit named imports across 100 test files under api/tests/integration/tests/.

  • AST-based analysis determined which env_indigo names each file actually uses
  • Removed redundant imports — stdlib modules (os, sys, threading) already imported directly are not re-imported from env_indigo
  • Moved threading to direct import threading in 4 files that previously obtained it through the wildcard

Import style:

# ≤3 names: single line
from env_indigo import Indigo, joinPathPy

# >3 names: parenthesized multi-line
from env_indigo import (
    Indigo,
    IndigoException,
    getIndigoExceptionText,
    joinPathPy,
)

Only files listed in the issue were modified. deco/extract_scaffold.py (not in scope) is unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>Refactor: Wildcard imports should not be used</issue_title>
<issue_description>Problem:
Import only needed names or import the module and then use its members.

Why is this an issue?
Importing every public name from a module using a wildcard (from mymodule import *) is a bad idea because:

  • It could lead to conflicts between names defined locally and the ones imported.
  • It reduces code readability as developers will have a hard time knowing where names come from.
  • It clutters the local namespace, which makes debugging more difficult.

Remember that imported names can change when you update your dependencies. A wildcard import that works today might be broken tomorrow.
Exceptions

No issue will be raised in __init__.py files. Wildcard imports are a common way of populating these modules.

No issue will be raised in modules doing only imports. Local modules are sometimes created as a proxy for third-party modules.

# file: mylibrary/pyplot.py
try:
    from guiqwt.pyplot import *  # Ok
except Exception:
    from matplotlib.pyplot import *  # Ok

Just keep in mind that wildcard imports might still create issues in these cases. It’s always better to import only what you need.

How can I fix it?
There are two ways to avoid a wildcard import:

  • Replace it with import mymodule and access module members as mymodule.myfunction. If the module name is too long, alias it to a shorter name. Example: import pandas as pd
  • List every imported name. If necessary import statements can be split on multiple lines using parentheses (preferred solution) or backslashes.

Noncompliant code example

from math import *  # Noncompliant
def exp(x):
    pass
print(exp(0))   # "None" will be printed

Compliant solution

import math
def exp(x):
    pass
print(math.exp(0))   # "1.0" will be printed

Or

from math import exp as m_exp
def exp(x):
    pass
print(m_exp(0))   # "1.0" will be printed

NOTE: Resulted code shoul follow clang-format formating.

Problem locations:
api/tests/integration/tests/aam/aam_access.py
api/tests/integration/tests/aam/aam_basic.py
api/tests/integration/tests/aam/aam_hard.py
api/tests/integration/tests/arom/arom_d_orbital.py
api/tests/integration/tests/arom/arom_merge.py
api/tests/integration/tests/arom/basic.py
api/tests/integration/tests/arom/elements.py
api/tests/integration/tests/arom/extended.py
api/tests/integration/tests/arom/partial_arom_cano.py
api/tests/integration/tests/arom/query_dearom.py
api/tests/integration/tests/basic/allenes.py
api/tests/integration/tests/basic/atom_bond_indicies.py
api/tests/integration/tests/basic/attachment_points.py
api/tests/integration/tests/basic/badval_smiles.py
api/tests/integration/tests/basic/basic.py
api/tests/integration/tests/basic/basic_check.py
api/tests/integration/tests/basic/basic_load.py
api/tests/integration/tests/basic/buffer_string_load_iterate.py
api/tests/integration/tests/basic/check_query.py
api/tests/integration/tests/basic/chiral_test.py
api/tests/integration/tests/basic/cis_trans.py
api/tests/integration/tests/basic/components.py
api/tests/integration/tests/basic/create_query.py
api/tests/integration/tests/basic/debug.py
api/tests/integration/tests/basic/exceptions.py
api/tests/integration/tests/basic/fischer_proj.py
api/tests/integration/tests/basic/fold_then_smiles.py
api/tests/integration/tests/basic/fold_unfold.py
api/tests/integration/tests/basic/get_original_format.py
api/tests/integration/tests/basic/hash.py
api/tests/integration/tests/basic/highlighting.py
api/tests/integration/tests/basic/hybridization.py
api/tests/integration/tests/basic/imp_h_test.py
api/tests/integration/tests/basic/imp_h_test_ket.py
api/tests/integration/tests/basic/ketfile_stereo_desc.py
api/tests/integration/tests/basic/leak.py
api/tests/integration/tests/basic/load.py
api/tests/integration/tests/basic/load_dearom_save.py
api/tests/integration/tests/basic/load_structure.py
api/tests/integration/tests/basic/molfile_stereo_desc.py
api/tests/integration/tests/basic/molfile_stereoparity.py
api/tests/integration/tests/basic/multiple_instances.py
api/tests/integration/tests/basic/murcko.py
api/tests/integration/tests/basic/options.py
api/tests/integration/tests/basic/properties.py
api/tests/integration/tests/basic/pseudoatoms.py
api/tests/integration/tests/basic/query_instrumentation.py
api/tests/integration/tests/basic/radicals.py
api/tests/integration/tests/basic/reaction_instrumentation.py
api/tests/integration/tests/basic/reaction_saveload.py
api/tests/integration/tests/basic/rings.py
api/tests/integration/tests/basic/rsite.py
api/tests/integration/tests/basic/savers.py
api/tests/integration/tests/basic/scsr_basic.py
api/tests/integration/tests/basic/scsr_instrumentation.py
api/tests/integration/tests/basic/set_charge.py
api/tests/integration/tests/basic/sssr.py
api/tests/integration/tests/basic/stereo_test.py
api/test...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 20, 2026 14:47
Replace `from env_indigo import *` with explicit named imports in all
files listed in the issue. Standard library modules (os, sys, etc.)
that are already directly imported are not redundantly imported from
env_indigo.

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Import threading directly as a standard library module instead of
getting it through env_indigo in threads_test.py, molfile_stereo_desc.py,
and ketfile_stereo_desc.py.

Co-authored-by: AlexeyGirin <26869421+AlexeyGirin@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor to remove wildcard imports Refactor: Replace wildcard imports with explicit imports in integration test files Feb 20, 2026
Copilot AI requested a review from AlexeyGirin February 20, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Wildcard imports should not be used

2 participants