Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ajelenak committed Apr 6, 2024
1 parent 26f6c56 commit a9d3770
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions h5json/hdf5db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ def getAttributeItemByObj(self, obj, name, includeData=True):
# todo - don't include data for OPAQUE until JSON serialization
# issues are addressed

if type(typeItem) == dict and typeItem["class"] in ("H5T_OPAQUE"):
if isinstance(typeItem, dict) and typeItem["class"] in ("H5T_OPAQUE"):
includeData = False

shape_json = self.getShapeItemByAttrObj(attrObj)
Expand Down Expand Up @@ -1461,7 +1461,7 @@ def makeAttribute(self, obj, attr_name, shape, attr_type, value):
strPad = None
strLength = 0
if (
type(attr_type) == dict
isinstance(attr_type, dict)
and attr_type["class"] == "H5T_STRING"
and "strPad" in attr_type
):
Expand All @@ -1470,7 +1470,7 @@ def makeAttribute(self, obj, attr_name, shape, attr_type, value):

if (
rank == 0
and type(strLength) == int
and isinstance(strLength, int)
and strPad == "H5T_STR_NULLTERM"
):
self.makeNullTermStringAttribute(obj, attr_name, strLength, value)
Expand Down Expand Up @@ -1693,7 +1693,7 @@ def getRefValue(self, typeItem: dict, value: list):
self.log.info(msg)
raise IOError(errno.ENINVAL, msg)

if type(out) == list:
if isinstance(out, list):
out = tuple(out) # convert to tuple
return out

Expand Down Expand Up @@ -1926,11 +1926,11 @@ def listToRef(self, data):
else:
out = obj_ref

elif type(data) in (list, tuple):
elif isinstance(data, (list, tuple)):
out = []
for item in data:
out.append(self.listToRef(item)) # recursive call
elif type(data) == dict:
elif isinstance(data, dict):
# assume region ref
out = self.createRegionReference(data)
else:
Expand Down Expand Up @@ -2096,15 +2096,15 @@ def createRegionReference(self, item):
self.log.info(msg)
raise IOError(errno.EINVAL, msg)
start = slab[0]
if type(start) == list:
if isinstance(start, list):
start = tuple(start)
if type(start) is not tuple or len(start) != rank:
msg = "selection value not valid, start element should have number "
msg += "elements equal to rank of referenced dataset"
self.log.info(msg)
raise IOError(errno.EINVAL, msg)
stop = slab[1]
if type(stop) == list:
if isinstance(stop, list):
stop = tuple(stop)
if type(stop) is not tuple or len(stop) != rank:
msg = "selection value not valid, count element should have number "
Expand Down Expand Up @@ -2191,12 +2191,12 @@ def getDatasetValuesByUuid(self, obj_uuid, slices=Ellipsis, format="json"):
if val is None:
self.log.warning("no value returned from scalar dataset")

if type(slices) != list and type(slices) != tuple and slices is not Ellipsis:
if not isinstance(slices, (list, tuple)) and slices is not Ellipsis:
msg = "Unexpected error: getDatasetValuesByUuid: bad type for dim parameter"
self.log.error(msg)
raise IOError(errno.EIO, msg)

if (type(slices) == list or type(slices) == tuple) and len(slices) != rank:
if isinstance(slices, (list, tuple)) and len(slices) != rank:
msg = "Unexpected error: getDatasetValuesByUuid: number of dims in selection not same as rank"
self.log.error(msg)
raise IOError(errno.EIO, msg)
Expand Down Expand Up @@ -2507,7 +2507,7 @@ def setDatasetValuesByUuid(self, obj_uuid, data, slices=None, format="json"):
slices.append(s)
slices = tuple(slices)

if type(slices) != tuple:
if not isinstance(slices, tuple):
msg = "setDatasetValuesByUuid: bad type for dim parameter"
self.log.error(msg)
raise IOError(errno.EIO, msg)
Expand Down
18 changes: 9 additions & 9 deletions h5json/hdf5dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def getTypeResponse(typeItem):
response = {} # otherwise, return full type
for k in typeItem.keys():
if k == "base":
if type(typeItem[k]) == dict:
if isinstance(typeItem[k], dict):
response[k] = getTypeResponse(typeItem[k]) # recursive call
else:
response[k] = typeItem[k] # predefined type
Expand Down Expand Up @@ -89,7 +89,7 @@ def getItemSize(typeItem):
raise TypeError("Invalid Type")
# none of the expect primative types mathched
raise TypeError("Invalid Type")
if type(typeItem) != dict:
if not isinstance(typeItem, dict):
raise TypeError("invalid type")

item_size = 0
Expand Down Expand Up @@ -143,7 +143,7 @@ def getItemSize(typeItem):
raise KeyError("no 'field' elements provided")
# add up the size of each sub-field
for field in fields:
if type(field) != dict:
if not isinstance(field, dict):
raise TypeError("Expected dictionary type for field")
if "type" not in field:
raise KeyError("'type' missing from field")
Expand Down Expand Up @@ -210,7 +210,7 @@ def getTypeItem(dt):
#
# check for h5py variable length extension
vlen_check = check_dtype(vlen=dt.base)
if vlen_check is not None and type(vlen_check) != np.dtype:
if vlen_check is not None and not isinstance(vlen_check, np.dtype):
vlen_check = np.dtype(vlen_check)
ref_check = check_dtype(ref=dt.base)
if vlen_check == bytes:
Expand Down Expand Up @@ -364,7 +364,7 @@ def createBaseDataType(typeItem):
dtRet = np.dtype(dtName)
return dtRet # return predefined type

if type(typeItem) != dict:
if not isinstance(typeItem, dict):
raise TypeError("Type Error: invalid type")

if "class" not in typeItem:
Expand Down Expand Up @@ -402,7 +402,7 @@ def createBaseDataType(typeItem):
raise TypeError("unexpected 'charSet' value")
else:
nStrSize = typeItem["length"]
if type(nStrSize) != int:
if not isinstance(nStrSize, int):
raise TypeError("expecting integer value for 'length'")
type_code = None
if typeItem["charSet"] == "H5T_CSET_ASCII":
Expand Down Expand Up @@ -449,7 +449,7 @@ def createBaseDataType(typeItem):

dt_base = createDataType(arrayBaseType)

if type(typeItem["dims"]) == int:
if isinstance(typeItem["dims"], int):
dims = typeItem["dims"] # make into a tuple
elif type(typeItem["dims"]) not in (list, tuple):
raise TypeError("expected list or integer for dims")
Expand Down Expand Up @@ -518,7 +518,7 @@ def createDataType(typeItem):
dtRet = np.dtype(dtName)
return dtRet # return predefined type

if type(typeItem) != dict:
if not isinstance(typeItem, dict):
raise TypeError("invalid type")

if "class" not in typeItem:
Expand All @@ -536,7 +536,7 @@ def createDataType(typeItem):
subtypes = []
for field in fields:

if type(field) != dict:
if not isinstance(field, dict):
raise TypeError("Expected dictionary type for field")
if "name" not in field:
raise KeyError("'name' missing from field")
Expand Down
6 changes: 3 additions & 3 deletions h5json/jsontoh5/jsontoh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ def createDataset(self, uuid, body):
shape = body["shape"]
if shape["class"] == "H5S_SIMPLE":
dims = shape["dims"]
if type(dims) == int:
if isinstance(dims, int):
# convert int to array
dim1 = shape
dims = [dim1]
if "maxdims" in shape:
max_shape = shape["maxdims"]
if type(max_shape) == int:
if isinstance(max_shape, int):
# convert to array
dim1 = max_shape
max_shape = [dim1]
Expand Down Expand Up @@ -114,7 +114,7 @@ def createAttribute(self, attr_json, col_name, uuid):
shape = attr_json["shape"]
if shape["class"] == "H5S_SIMPLE":
dims = shape["dims"]
if type(dims) == int:
if isinstance(dims, int):
# convert int to array
dim1 = shape
dims = [dim1]
Expand Down

0 comments on commit a9d3770

Please sign in to comment.