Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 642891897
  • Loading branch information
tomvdw authored and SeqIO committed Jun 14, 2024
1 parent eee8190 commit c0ce514
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions seqio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,7 @@ def _get_builder(self, split: Optional[str] = None):
if builder_key not in LazyTfdsLoader._MEMOIZED_BUILDERS:
if dataset:
builder_kwargs = self._builder_kwargs if self._builder_kwargs else {}
builder = tfds.builder(
dataset, data_dir=data_dir, **builder_kwargs
)
builder = tfds.builder(dataset, data_dir=data_dir, **builder_kwargs)
else:
if self._builder_kwargs:
raise ValueError(
Expand Down Expand Up @@ -1555,13 +1553,21 @@ def fully_qualified_class_name(instance: Any) -> str:

def function_name(function) -> str:
"""Returns the name of a (possibly partially applied) function."""
if inspect.isclass(function):
# function can be a protocol.
return function.__class__.__name__
elif isinstance(function, functools.partial):
# functools.partial can be applied multiple times.
return function_name(function.func)
else:
return function.__name__
try:
if inspect.isclass(function):
# function can be a protocol.
if hasattr(function.__class__, "__name__"):
return function.__class__.__name__
else:
return str(function.__class__)
elif isinstance(function, functools.partial):
# functools.partial can be applied multiple times.
return function_name(function.func)
elif hasattr(function, "__name__"):
return function.__name__
except Exception: # pylint: disable=broad-exception-caught
pass
# Function name could not be determined.
return ""


0 comments on commit c0ce514

Please sign in to comment.