Skip to content

[debug] solve TYPE_CHECKING problem in shape.py#335

Open
wuxinxin27 wants to merge 1 commit into
DexForce:mainfrom
wuxinxin27:fix_shapecfg_type_checking
Open

[debug] solve TYPE_CHECKING problem in shape.py#335
wuxinxin27 wants to merge 1 commit into
DexForce:mainfrom
wuxinxin27:fix_shapecfg_type_checking

Conversation

@wuxinxin27

Copy link
Copy Markdown
Contributor

Description

Currently, the VisualMaterialCfg type in shape.py is imported only for static type checking and not at runtime; however, the ShapeCfg.from_dict function uses VisualMaterialCfg, resulting in a runtime error.

Fixes # (issue)
Simply import VisualMaterialCfg inside the ShapeCfg.from_dict function.

       for key, value in init_dict.items():
            if hasattr(cfg, key):
                attr = getattr(cfg, key)
                if key == "visual_material" and isinstance(value, dict):
                    from embodichain.lab.sim.material import VisualMaterialCfg

                    setattr(
                        cfg,
                        key,
                        VisualMaterialCfg.from_dict(value),
                    )

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have run the black . command to format the code base.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Dependencies have been updated, if applicable.

Copilot AI review requested due to automatic review settings June 27, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime crash in ShapeCfg.from_dict when visual_material is provided as a dict by importing VisualMaterialCfg at runtime (instead of only under TYPE_CHECKING). This aligns ShapeCfg.from_dict behavior with how config dicts are used when constructing objects (e.g., via RigidObjectCfg.from_dict).

Changes:

  • Add a local runtime import of VisualMaterialCfg inside ShapeCfg.from_dict when parsing visual_material from a dict.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 79 to +84
for key, value in init_dict.items():
if hasattr(cfg, key):
attr = getattr(cfg, key)
if key == "visual_material" and isinstance(value, dict):
from embodichain.lab.sim.material import VisualMaterialCfg

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.

3 participants