def _add_dataclass_arguments(self, dtype: DataClassType):
    for field in dataclasses.fields(dtype):
        if (not field.init):
            continue
        field_name = f'--{field.name}'
        kwargs = field.metadata.copy()
        if isinstance(field.type, str):
            raise ImportError('This implementation is not compatible with Postponed Evaluation of Annotations (PEP 563),which can be opted in from Python 3.7 with `from __future__ import annotations`.We will add compatibility when Python 3.9 is released.')
        typestring = str(field.type)
        for prim_type in (int, float, str):
            for collection in (List,):
                if ((typestring == f'typing.Union[{collection[prim_type]}, NoneType]') or (typestring == f'typing.Optional[{collection[prim_type]}]')):
                    field.type = collection[prim_type]
            if ((typestring == f'typing.Union[{prim_type.__name__}, NoneType]') or (typestring == f'typing.Optional[{prim_type.__name__}]')):
                field.type = prim_type
        if (isinstance(field.type, type) and issubclass(field.type, Enum)):
            kwargs['choices'] = [x.value for x in field.type]
            kwargs['type'] = type(kwargs['choices'][0])
            if (field.default is not dataclasses.MISSING):
                kwargs['default'] = field.default
            else:
                kwargs['required'] = True
        elif ((field.type is bool) or (field.type == Optional[bool])):
            if (field.default is True):
                self.add_argument(f'--no_{field.name}', action='store_false', dest=field.name, **kwargs)
            kwargs['type'] = string_to_bool
            if ((field.type is bool) or ((field.default is not None) and (field.default is not dataclasses.MISSING))):
                default = (True if (field.default is dataclasses.MISSING) else field.default)
                kwargs['default'] = default
                kwargs['nargs'] = '?'
                kwargs['const'] = True
        elif (hasattr(field.type, '__origin__') and (re.search('^typing\\.List\\[(.*)\\]$', str(field.type)) is not None)):
            kwargs['nargs'] = '+'
            kwargs['type'] = field.type.__args__[0]
            assert all(((x == kwargs['type']) for x in field.type.__args__)), f'{field.name} cannot be a List of mixed types'
            if (field.default_factory is not dataclasses.MISSING):
                kwargs['default'] = field.default_factory()
            elif (field.default is dataclasses.MISSING):
                kwargs['required'] = True
        else:
            kwargs['type'] = field.type
            if (field.default is not dataclasses.MISSING):
                kwargs['default'] = field.default
            elif (field.default_factory is not dataclasses.MISSING):
                kwargs['default'] = field.default_factory()
            else:
                kwargs['required'] = True
        self.add_argument(field_name, **kwargs)
def _add_dataclass_arguments(self, dtype: DataClassType):
    for field in dataclasses.fields(dtype):
        if (not field.init):
            continue
        field_name = f'--{field.name}'
        kwargs = field.metadata.copy()
        if isinstance(field.type, str):
            raise ImportError('This implementation is not compatible with Postponed Evaluation of Annotations (PEP 563),which can be opted in from Python 3.7 with `from __future__ import annotations`.We will add compatibility when Python 3.9 is released.')
        typestring = str(field.type)
        for prim_type in (int, float, str):
            for collection in (List,):
                if ((typestring == f'typing.Union[{collection[prim_type]}, NoneType]') or (typestring == f'typing.Optional[{collection[prim_type]}]')):
                    field.type = collection[prim_type]
            if ((typestring == f'typing.Union[{prim_type.__name__}, NoneType]') or (typestring == f'typing.Optional[{prim_type.__name__}]')):
                field.type = prim_type
        if (isinstance(field.type, type) and issubclass(field.type, Enum)):
            kwargs['choices'] = [x.value for x in field.type]
            kwargs['type'] = type(kwargs['choices'][0])
            if (field.default is not dataclasses.MISSING):
                kwargs['default'] = field.default
            else:
                kwargs['required'] = True
        elif ((field.type is bool) or (field.type == Optional[bool])):
            if (field.default is True):
                self.add_argument(f'--no_{field.name}', action='store_false', dest=field.name, **kwargs)
            kwargs['type'] = string_to_bool
            if ((field.type is bool) or ((field.default is not None) and (field.default is not dataclasses.MISSING))):
                default = (True if (field.default is dataclasses.MISSING) else field.default)
                kwargs['default'] = default
                kwargs['nargs'] = '?'
                kwargs['const'] = True
        elif (hasattr(field.type, '__origin__') and (re.search('^typing\\.List\\[(.*)\\]$', str(field.type)) is not None)):
            kwargs['nargs'] = '+'
            kwargs['type'] = field.type.__args__[0]
            assert all(((x == kwargs['type']) for x in field.type.__args__)), f'{field.name} cannot be a List of mixed types'
            if (field.default_factory is not dataclasses.MISSING):
                kwargs['default'] = field.default_factory()
            elif (field.default is dataclasses.MISSING):
                kwargs['required'] = True
        else:
            kwargs['type'] = field.type
            if (field.default is not dataclasses.MISSING):
                kwargs['default'] = field.default
            elif (field.default_factory is not dataclasses.MISSING):
                kwargs['default'] = field.default_factory()
            else:
                kwargs['required'] = True
        self.add_argument(field_name, **kwargs)