fix(tidy3d_extras): fix error message in tidy3d_extras importing #3004
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Greptile Overview
Greptile Summary
This PR improves error messaging in the
tidy3d_extrasimport checking function by:pip install tidy3d\[extras]) to prevent them from being interpreted as glob patterns in some shells__version__attribute existence before attempting to access it, providing a clearer error message when the package didn't initialize properlyIssue Found:
Confidence Score: 4/5
__version__check provides better error handling. One syntax issue (missing space) needs correction before merging.Important Files Changed
File Analysis
__version__check; missing space after period on line 215Sequence Diagram
sequenceDiagram participant User participant Function as _check_tidy3d_extras_available() participant ImportSystem as Import System participant Module as tidy3d_extras module User->>Function: Call function requiring tidy3d_extras Function->>Function: Check if already loaded (tidy3d_extras["mod"]) alt Already loaded Function-->>User: Return (skip checks) end Function->>ImportSystem: find_spec("tidy3d_extras") alt Module not found ImportSystem-->>Function: None Function->>User: Raise error with escaped brackets end Function->>Module: import tidy3d_extras alt Import fails Module-->>Function: ImportError Function->>User: Raise Tidy3dImportError end Function->>Module: Check hasattr(__version__) alt __version__ missing (NEW CHECK) Module-->>Function: False Function->>User: Raise error with install instructions end Function->>Module: Get __version__ alt version is None Module-->>Function: None Function->>User: Raise error (invalid API key) end alt version mismatch Function->>User: Raise error with version info end Function->>Function: Store module reference Function-->>User: Success