AGENT SKILL

coding.fix_bloated_imports

Fix Python imports of large packages needed only for few functions in a module

License 许可
Apache-2.0
所属仓库
causify-ai/helpers
最近更新
2026-11-02
Stars
★ 0
Forks
1

01 前言 Front Matter

model
haiku
description
Fix Python imports of large packages needed only for few functions in a module

03 SKILL.md 正文

  • I will pass you one or more files <FILES> and one or more packages <PACKAGES> that are usually large to import (e.g., ipython, pandas) and are needed only in few functions in the files

  • In the files <FILES> you will use a conditional import for type checking and lazy imports for <PACKAGES>

    • E.g., transform
      def make_slider() -> "ipywidgets.IntSlider":
          import ipywidgets
          ...
      
      into
      from typing import TYPE_CHECKING
      
      if TYPE_CHECKING:
          import ipywidgets
      
      def make_slider() -> "ipywidgets.IntSlider":
          import ipywidgets
          ...
      
  • Use forward references only for the types in the package to remove and not for the including

    • Bad (quotes the whole expression as one string)
      "Tuple[Union[ipywidgets.FloatSlider, ipywidgets.IntSlider], ipywidgets.HBox]"
      
    • Good (quotes only the package types)
      Tuple[Union["ipywidgets.FloatSlider", "ipywidgets.IntSlider"], "ipywidgets.HBox"]
      
  • If you see that most of the functions in <FILES> require the passed package <PACKAGES>, you might suggest to not do this transform

Verification

  • [ ] Confirm <PACKAGES> is imported only under TYPE_CHECKING or inside the functions that use it
  • [ ] Confirm forward references quote only the package types, not full expressions

04 同仓库更多 Skills