This issue is part of a Codex global repository code scan.
DataType.__init__() documents dtype as "type or tuple[type]", and check() uses isinstance(data, self.dtype), which supports tuple dtypes. However, error and repr formatting use self.dtype.__name__, which raises AttributeError when dtype is a tuple.
Affected code:
|
dtype : type or tuple[type] |
|
data type, e.g. np.ndarray |
|
shape : tuple[int], optional |
|
return ( |
|
f"DataType(name='{self.name}', dtype={self.dtype.__name__}, " |
|
f"shape={self.shape}, required={self.required}, " |
|
f"deepmd_name='{self.deepmd_name}')" |
|
elif not isinstance(data, self.dtype): |
|
raise DataError( |
|
f"Type of {self.name} is {type(data).__name__}, but expected {self.dtype.__name__}" |
|
) |
Minimal reproducer:
from dpdata.data_type import DataType
print(repr(DataType("x", (list, tuple))))
Current behavior:
AttributeError: 'tuple' object has no attribute '__name__'
The same issue occurs in check() when reporting a type mismatch. Either tuple dtypes should be supported in formatting, or the documented accepted type should be narrowed.
This issue is part of a Codex global repository code scan.
DataType.__init__()documentsdtypeas "type or tuple[type]", andcheck()usesisinstance(data, self.dtype), which supports tuple dtypes. However, error and repr formatting useself.dtype.__name__, which raisesAttributeErrorwhendtypeis a tuple.Affected code:
dpdata/dpdata/data_type.py
Lines 42 to 44 in a7a50bf
dpdata/dpdata/data_type.py
Lines 98 to 101 in a7a50bf
dpdata/dpdata/data_type.py
Lines 146 to 149 in a7a50bf
Minimal reproducer:
Current behavior:
The same issue occurs in
check()when reporting a type mismatch. Either tuple dtypes should be supported in formatting, or the documented accepted type should be narrowed.