STRUCT003warningPro

imports-in-function

Import statement inside a function instead of at module level.

Applies to: Python

Why this matters

Imports should be at the top of the file for clarity and performance. Imports inside functions run every time the function is called, and they hide dependencies. The only exception is avoiding circular imports, which usually indicates a design problem.

Catch it before it ships

pip install stablestack # or: npx stablestackstablestack # scans your project, STRUCT003 includedstablestack explain STRUCT003

STRUCT003 is part of the Pro rule set. See pricing — the free tier ships 24 checks with no signup.

False positive in your codebase? Suppress a single line with # noqa: STRUCT003