conditional-imports

Refactor Python conditional imports into Protocol-based interfaces.

6|2|Updated Apr 19, 2026
One-click install
npx skills add https://github.com/paudley/coding-ethos --skill conditional-imports
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: conditional-imports
Source: https://github.com/paudley/coding-ethos/tree/main/.gemini/extensions/coding-ethos/skills/conditional-imports
Command: npx skills add https://github.com/paudley/coding-ethos --skill conditional-imports

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps fix Python code that relies on conditional imports, type-checking branches, or hiding dependencies, enabling clearer, more reliable module boundaries.

Core Features & Use Cases

  • Identify conditional import patterns such as if TYPE_CHECKING or try-except import blocks.
  • Refactor codebases to replace conditional dependencies with explicit protocols and dependency inversion principles.
  • Use Case: A developer notices cyclic import issues caused by environment-dependent imports and wants to enforce consistent, environment-agnostic dependencies across modules.

Quick Start

Use this Skill to convert conditional import statements into strict, Protocol-based interfaces appropriate for production code.

Frequently Asked Questions about conditional-imports

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix cyclic imports caused by conditional imports in Python?

To fix cyclic imports caused by conditional imports, refactor the codebase to replace conditional dependencies with explicit protocols and dependency inversion principles. This enforces consistent, environment-agnostic module boundaries and resolves cyclic import problems.

What is the best way to handle TYPE_CHECKING blocks for runtime dependencies?

The best way to handle TYPE_CHECKING blocks is to promote protocol-first design and strict dependency handling. This approach verifies interfaces and enforces SOLID principles, avoiding runtime masking of missing dependencies and ensuring safer code structures.

How do I refactor try-except import blocks to prevent missing dependency masking?

Refactoring try-except import blocks involves replacing them with strict, Protocol-based interfaces appropriate for production code. This ensures code adheres to best practices for module dependencies and avoids hiding missing dependencies.

Can I use Python protocols to enforce SOLID principles across module boundaries?

Yes, you can use Python protocols to enforce SOLID principles across module boundaries. The refactoring process promotes protocol-first design and strict dependency handling, verifying interfaces to ensure cleaner, safer code structures.

Why does hiding dependencies in conditional imports cause runtime errors?

Hiding dependencies in conditional imports causes runtime errors because environment-dependent imports mask missing dependencies and create cyclic import issues. Strict dependency handling and protocol-based design eliminate this masking for reliable module boundaries.

Does refactoring to protocol-based design work for existing Python codebases with local imports?

Yes, refactoring to protocol-based design works for existing Python codebases with local imports. The process identifies conditional import patterns and transforms them into strict, Protocol-based interfaces appropriate for production code.