MCPcopy
hub / github.com/pytorch/vision / verify_str_arg

Function verify_str_arg

torchvision/datasets/utils.py:401–426  ·  view source on GitHub ↗
(
    value: T,
    arg: Optional[str] = None,
    valid_values: Optional[Iterable[T]] = None,
    custom_msg: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

399
400
401def verify_str_arg(
402 value: T,
403 arg: Optional[str] = None,
404 valid_values: Optional[Iterable[T]] = None,
405 custom_msg: Optional[str] = None,
406) -> T:
407 if not isinstance(value, str):
408 if arg is None:
409 msg = "Expected type str, but got type {type}."
410 else:
411 msg = "Expected type str for argument {arg}, but got type {type}."
412 msg = msg.format(type=type(value), arg=arg)
413 raise ValueError(msg)
414
415 if valid_values is None:
416 return value
417
418 if value not in valid_values:
419 if custom_msg is not None:
420 msg = custom_msg
421 else:
422 msg = "Unknown value '{value}' for argument {arg}. Valid values are {{{valid_values}}}."
423 msg = msg.format(value=value, arg=arg, valid_values=iterable_to_str(valid_values))
424 raise ValueError(msg)
425
426 return value
427
428
429def _read_pfm(file_name: Union[str, pathlib.Path], slice_channels: int = 2) -> np.ndarray:

Callers 15

__init__Method · 0.90
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls 1

iterable_to_strFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…