Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/transformers/hf_argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def _parse_dataclass_field(parser: ArgumentParser, field: dataclasses.Field):

origin_type = getattr(field.type, "__origin__", field.type)
if origin_type is Union:
if len(field.type.__args__) != 2 or type(None) not in field.type.__args__:
if str not in field.type.__args__ and (
len(field.type.__args__) != 2 or type(None) not in field.type.__args__
):
raise ValueError(
"Only `Union[X, NoneType]` (i.e., `Optional[X]`) is allowed for `Union` because"
" the argument parser only supports one type per argument."
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def to_tuple(self) -> Tuple[Any]:
return tuple(self[k] for k in self.keys())


class ExplicitEnum(Enum):
class ExplicitEnum(str, Enum):
"""
Enum with more explicit error message for missing values.
"""
Expand Down