Skip to content

Commit

Permalink
remove use of util.is_string
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Sep 26, 2024
1 parent 9f13cd5 commit 875c54e
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 17 deletions.
10 changes: 5 additions & 5 deletions trimesh/exchange/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def export_mesh(mesh, file_obj, file_type=None, resolver=None, **kwargs):
# handle `pathlib` objects by converting to string
file_obj = str(file_obj.absolute())

if util.is_string(file_obj):
if isinstance(file_obj, str):
if file_type is None:
# get file type from file name
file_type = (str(file_obj).split(".")[-1]).lower()
Expand Down Expand Up @@ -247,7 +247,7 @@ def export_scene(scene, file_obj, file_type=None, resolver=None, **kwargs):

# if we weren't passed a file type extract from file_obj
if file_type is None:
if util.is_string(file_obj):
if isinstance(file_obj, str):
file_type = str(file_obj).split(".")[-1]
else:
raise ValueError("file_type not specified!")
Expand All @@ -266,7 +266,7 @@ def export_scene(scene, file_obj, file_type=None, resolver=None, **kwargs):
# if we are exporting by name automatically create a
# resolver which lets the exporter write assets like
# the materials and textures next to the exported mesh
if resolver is None and util.is_string(file_obj):
if resolver is None and isinstance(file_obj, str):
resolver = resolvers.FilePathResolver(file_obj)
data = export_obj(scene, resolver=resolver, **kwargs)
elif file_type == "dict64":
Expand All @@ -290,7 +290,7 @@ def export_scene(scene, file_obj, file_type=None, resolver=None, **kwargs):
# represent multiple files so create a filepath
# resolver and write the files if someone passed
# a path we can write to.
if resolver is None and util.is_string(file_obj):
if resolver is None and isinstance(file_obj, str):
resolver = resolvers.FilePathResolver(file_obj)
# the requested "gltf"
bare_path = os.path.split(file_obj)[-1]
Expand All @@ -306,7 +306,7 @@ def export_scene(scene, file_obj, file_type=None, resolver=None, **kwargs):
if hasattr(file_obj, "write"):
# if it's just a regular file object
return util.write_encoded(file_obj, data)
elif util.is_string(file_obj):
elif isinstance(file_obj, str):
# assume strings are file paths
file_path = os.path.abspath(os.path.expanduser(file_obj))
with open(file_path, "wb") as f:
Expand Down
4 changes: 2 additions & 2 deletions trimesh/exchange/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def _parse_file_args(

if util.is_file(file_obj) and file_type is None:
raise ValueError("file_type must be set for file objects!")
if util.is_string(file_obj):
if isinstance(file_obj, str):
try:
# os.path.isfile will return False incorrectly
# if we don't give it an absolute path
Expand Down Expand Up @@ -614,7 +614,7 @@ def _parse_file_args(
if file_type is None:
file_type = file_obj.__class__.__name__

if util.is_string(file_type) and "." in file_type:
if isinstance(file_type, str) and "." in file_type:
# if someone has passed the whole filename as the file_type
# use the file extension as the file_type
if "file_path" not in metadata:
Expand Down
2 changes: 1 addition & 1 deletion trimesh/exchange/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def load_dict(data, **kwargs):
raise ValueError("data passed to load_dict was None!")
if util.is_instance_named(data, "Trimesh"):
return data
if util.is_string(data):
if isinstance(data, str):
if "{" not in data:
raise ValueError("Object is not a JSON encoded dictionary!")
data = json.loads(data.decode("utf-8"))
Expand Down
2 changes: 1 addition & 1 deletion trimesh/path/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def __init__(
if align is None:
# if not set make everything centered
align = ["center", "center"]
elif util.is_string(align):
elif isinstance(align, str):
# if only one is passed set for both
# horizontal and vertical
align = [align, align]
Expand Down
2 changes: 1 addition & 1 deletion trimesh/path/exchange/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def export_path(path, file_type=None, file_obj=None, **kwargs):
"""
# if file object is a string it is probably a file path
# so we can split the extension to set the file type
if util.is_string(file_obj):
if isinstance(file_obj, str):
file_type = util.split_extension(file_obj)

# run the export
Expand Down
2 changes: 1 addition & 1 deletion trimesh/path/exchange/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def load_path(file_obj, file_type=None, **kwargs):
kwargs.update(load_ply(file_obj, file_type=file_type))
else:
kwargs.update(path_loaders[file_type](file_obj, file_type=file_type))
elif util.is_string(file_obj):
elif isinstance(file_obj, str):
# strings passed are evaluated as file file_objects
with open(file_obj, "rb") as f:
# get the file type from the extension
Expand Down
7 changes: 3 additions & 4 deletions trimesh/path/exchange/svg_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def _encode(stuff):
encoded : str
Packaged into url-safe b64 string
"""
if util.is_string(stuff) and '"' not in stuff:
if isinstance(stuff, str) and '"' not in stuff:
return stuff
pack = base64.urlsafe_b64encode(
jsonify(
Expand Down Expand Up @@ -664,9 +664,8 @@ def _deep_same(original, other):
# but otherwise types should be identical
if isinstance(original, np.ndarray):
assert isinstance(other, (list, np.ndarray))
elif util.is_string(original):
# handle python 2+3 unicode vs str
assert util.is_string(other)
elif isinstance(original, str):
assert isinstance(other, str)
else:
# otherwise they should be the same type
assert isinstance(original, type(other))
Expand Down
2 changes: 1 addition & 1 deletion trimesh/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def delete_geometry(self, names: Union[set, str, Sequence]) -> None:
Name that references self.geometry
"""
# make sure we have a set we can check
if util.is_string(names):
if isinstance(names, str):
names = [names]
names = set(names)

Expand Down
2 changes: 1 addition & 1 deletion trimesh/scene/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def remove_geometries(self, geometries: Union[str, set, Sequence]):
Name of scene.geometry to dereference.
"""
# make sure we have a set of geometries to remove
if util.is_string(geometries):
if isinstance(geometries, str):
geometries = [geometries]
geometries = set(geometries)

Expand Down

0 comments on commit 875c54e

Please sign in to comment.