Skip to content

Remove star imports#4983

Draft
jasonb5 wants to merge 2 commits into
feat/refactor-core-foundationfrom
fix/refactor-star-imports
Draft

Remove star imports#4983
jasonb5 wants to merge 2 commits into
feat/refactor-core-foundationfrom
fix/refactor-star-imports

Conversation

@jasonb5

@jasonb5 jasonb5 commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Description

Removes wildcard (from ... import *) imports across the CIME Python codebase
and applies consistent PEP 8 import ordering to every file touched. Wildcard
imports hide a module's true dependencies, defeat static analysis, and let
unrelated symbols collide across modules.

Star imports removed (106 files)

  • 97 files — replaced from CIME.XML.standard_module_setup import * with
    explicit imports
  • 18 files — replaced from CIME.test_status import * with explicit imports
  • 9 files appear in both groups
  • from CIME.Tools.standard_script_setup import * in CIME/scripts/* is
    intentionally left in place (that module is the script bootstrap shim).

Import reordering (114 additional files)

Where imports were already explicit, the order was normalized to PEP 8 style:

  1. import a, b, c collapsed to one module per line
  2. Three groups separated by blank lines: stdlib → third-party → first-party (CIME)
  3. Each group alphabetized
  4. Symbols inside from X import (a, b, c) alphabetized

Backward compatibility preserved

  • CIME/XML/standard_module_setup.py — marked DEPRECATED in the docstring;
    explicit imports tagged # noqa: F401 so external code that still does
    from CIME.XML.standard_module_setup import * (E3SM, CESM, NorESM
    cime_config/) continues to receive the same names.
  • CIME/Tools/standard_script_setup.py — same treatment; also adds explicit
    re-exports of argparse and logging.

Totals

  • 220 files changed
  • +1,327 / −841 lines
  • No tooling/config changes (no pyproject.toml, setup.cfg, or .isort.cfg
    modified)

Test status

Running pytest CIME/tests/ -k test_unit (with CIME_MACHINE=linux-generic,
E3SM cime_config/) yields 11 failed, 378 passed, 13 skipped. The same
11 failures reproduce identically on master and on the base branch
feat/refactor-core-foundation (PR #4982). They are pre-existing issues
unrelated to this PR
— caused by E3SM machine-config / baseline mismatches
in the local test environment, not by import changes. Confirmed by running
the same suite on all three branches from clean worktrees.

Depends on: #4982

Checklist

  • My code follows the style guidelines of this project (black formatting)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that exercise my feature/fix and existing tests continue to pass
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding additions and changes to the documentation

@github-actions

Copy link
Copy Markdown
Contributor

@jasonb5 jasonb5 changed the base branch from master to feat/refactor-core-foundation June 18, 2026 20:21
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.

1 participant