[examples] Generate argparsers from type hints on dataclasses
Author: julien-c
Pull request: yes


Comments:
# [Codecov](https://codecov.io/gh/huggingface/transformers/pull/3669?src=pr&el=h1) Report
> Merging [#3669](https://codecov.io/gh/huggingface/transformers/pull/3669?src=pr&el=desc) into [master](https://codecov.io/gh/huggingface/transformers/commit/0a9d09b42a9c7c1ccc00da48486a1188078e8594&el=desc) will **increase** coverage by `0.03%`.
> The diff coverage is `83.54%`.

[![Impacted file tree graph](https://codecov.io/gh/huggingface/transformers/pull/3669/graphs/tree.svg?width=650&height=150&src=pr&token=9qOlN6Hb1c)](https://codecov.io/gh/huggingface/transformers/pull/3669?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #3669      +/-   ##
==========================================
+ Coverage   78.03%   78.07%   +0.03%     
==========================================
  Files         104      106       +2     
  Lines       17708    17787      +79     
==========================================
+ Hits        13819    13887      +68     
- Misses       3889     3900      +11     
```


| [Impacted Files](https://codecov.io/gh/huggingface/transformers/pull/3669?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/transformers/hf\_argparser.py](https://codecov.io/gh/huggingface/transformers/pull/3669/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9oZl9hcmdwYXJzZXIucHk=) | `74.00% <74.00%> (ø)` | |
| [src/transformers/\_\_init\_\_.py](https://codecov.io/gh/huggingface/transformers/pull/3669/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9fX2luaXRfXy5weQ==) | `98.98% <100.00%> (+0.02%)` | :arrow_up: |
| [src/transformers/training\_args.py](https://codecov.io/gh/huggingface/transformers/pull/3669/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy90cmFpbmluZ19hcmdzLnB5) | `100.00% <100.00%> (ø)` | |
| [src/transformers/modeling\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3669/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ191dGlscy5weQ==) | `92.23% <0.00%> (+0.12%)` | :arrow_up: |
| [src/transformers/modeling\_tf\_utils.py](https://codecov.io/gh/huggingface/transformers/pull/3669/diff?src=pr&el=tree#diff-c3JjL3RyYW5zZm9ybWVycy9tb2RlbGluZ190Zl91dGlscy5weQ==) | `93.28% <0.00%> (+0.16%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/huggingface/transformers/pull/3669?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/huggingface/transformers/pull/3669?src=pr&el=footer). Last update [0a9d09b...b63747d](https://codecov.io/gh/huggingface/transformers/pull/3669?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Phew! Ok, I went through multiple rewrites today and I think it is pretty good now.

**TL;DR:**

- I only made changes to the `run_glue.py` example script to keep the diff smaller.
- I have to pass `DataClassType`s (_types_, not instances) to `HfArgumentParser` because if they have required properties/arguments, we wouldn't be able to instantiate them before "filling" them
- The class is designed to play well with the native `argparse`. In particular, you can get back any not-known args and parse them using a different argparse.ArgumentParser, to make adoption easier in complex scripts.
- **read the unit tests for (a subset of) the supported arguments and how the properties translate into arguments.**