fix: handle tuple dtype in DataType repr and error message#1005
fix: handle tuple dtype in DataType repr and error message#1005CedricConday wants to merge 1 commit into
Conversation
DataType accepts dtype as a type or a tuple[type] (check() already uses isinstance with it), but __repr__ and the type-mismatch error formatted via self.dtype.__name__, which raised AttributeError for a tuple dtype. Add a small helper to render either form. Fixes deepmodeling#989 Assisted-by: Claude Opus 4.8
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds a Tuple dtype fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merging this PR will degrade performance by 10.13%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | WallTime | test_import |
10.1 ms | 11.2 ms | -10.13% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing CedricConday:fix/datatype-tuple-dtype-repr-989 (45338d8) with master (a7a50bf)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1005 +/- ##
==========================================
+ Coverage 86.68% 86.70% +0.01%
==========================================
Files 89 89
Lines 8120 8124 +4
==========================================
+ Hits 7039 7044 +5
+ Misses 1081 1080 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Fixes #989.
DataTypedocuments and supportsdtypeas atypeor atuple[type]—check()already usesisinstance(data, self.dtype), which is tuple-aware. But__repr__and the type-mismatch error incheck()formatted the dtype viaself.dtype.__name__, which raisesAttributeError: 'tuple' object has no attribute '__name__'wheneverdtypeis a tuple. Sorepr(DataType("x", (list, tuple)))crashes instead of returning a string.Changes
_dtype_name()helper that renders either a single type or a tuple of types.__repr__and in thecheck()error message.Testing
reprof a tuple-dtypeDataTypeno longer raises and lists both type names; a type mismatch against a tuple dtype raises a readableDataError(notAttributeError). Both fail onmasterand pass with this change.ruff checkclean; existingTestDataTypetests pass.Disclosure: authored with AI assistance (Claude Code); reviewed by me and I'll shepherd it through review.
Summary by CodeRabbit