mirror of
https://github.com/huggingface/transformers.git
synced 2025-08-02 11:11:05 +06:00
ExplicitEnum subclass str (JSON dump compatible) (#17933)
* ExplicitEnum subclass str (JSON dump compatible) * allow union if one of the types is str
This commit is contained in:
parent
b089cca347
commit
bc019b0e5f
@ -84,7 +84,9 @@ class HfArgumentParser(ArgumentParser):
|
||||
|
||||
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."
|
||||
|
@ -240,7 +240,7 @@ class ModelOutput(OrderedDict):
|
||||
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.
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user